pentaho/pentaho-kettle · error · KettleException

TextFileInputDialog.Exception.ErrorGettingFirstLines

Error message

TextFileInputDialog.Exception.ErrorGettingFirstLines

What it means

TextFileInputDialog's constructor (first-lines fetching, getFirstLines path) reads up to maxnr initial lines using TextFileLine/TextFile.getLine. Any exception while reading those lines is wrapped in a KettleException keyed to TextFileInputDialog.Exception.ErrorGettingFirstLines, including the number of lines read so far and the file URI, with the original exception as cause.

Solutions

  1. Verify the file exists and is readable at the configured location/URI
  2. Check the declared encoding matches the actual file encoding
  3. If the file is compressed, validate the archive is not corrupt (unzip -t / gunzip -t)
  4. Preview with a smaller number of sample lines and check file permissions/network access

Example fix

// before: reading a missing file
String filename = "/data/in/sales.csv"; // file moved -> IO error while sampling
// after: ensure path exists before opening dialog
if ( new File( "/data/in/sales.csv" ).exists() ) { openDialog( "/data/in/sales.csv" ); }
Defensive patterns

Strategy: try-catch

Validate before calling

// Java: verify the VFS file is resolvable and readable before sampling
org.apache.commons.vfs2.FileObject fo = KettleVFS.getFileObject( filename );
if ( !fo.exists() || !fo.isReadable() ) throw new IllegalStateException( "Cannot read: " + fo.getURI() );

Type guard

boolean fileReadable = filename != null && KettleVFS.fileExists( filename );

Try / catch

try { sampleFirstLines( file, maxnr ); } catch ( KettleException e ) { log.error( "Failed reading first lines of " + file.getName().getURI() + ": " + e.getCause(), e ); }

Prevention

When it happens

Trigger: Opening the Text File Input dialog / sampling the file when the underlying VFS file cannot be read — missing file, IO error on the input stream, unsupported/incorrect encoding, or a broken compressed (zip/gzip) stream while pulling the first n lines.

Common situations: File path points to a non-existent or moved file; permission denied on network share; wrong encoding declared; corrupt zip/gzip archive; VFS URL (file.getName().getURI()) invalid or unreachable.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/9399f429b9de92e5. Report an issue: GitHub.

Appendix: source

Thrown at ui/src/main/java/org/pentaho/di/ui/trans/steps/textfileinput/TextFileInputDialog.java:2922

          // Skip the header lines first if more then one, it helps us position
          if ( meta.hasHeader() && meta.getNrHeaderLines() > 0 ) {
            int skipped = 0;
            String line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );
            while ( line != null && skipped < meta.getNrHeaderLines() - 1 ) {
              skipped++;
              line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );
            }
          }
        }

        String line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );
        while ( line != null && ( linenr < maxnr || nrlines == 0 ) ) {
          retval.add( line );
          linenr++;
          line = TextFileInput.getLine( log, reader, encodingType, fileFormatType, lineStringBuilder );
        }
      } catch ( Exception e ) {
        throw new KettleException( BaseMessages.getString( PKG, "TextFileInputDialog.Exception.ErrorGettingFirstLines",
            "" + nrlines, file.getName().getURI() ), e );
      } finally {
        try {
          if ( f != null ) {
            f.close();
          }
        } catch ( Exception e ) {
          // Ignore errors
        }
      }
    }

    return retval;
  }

  private void getFixed() {
    TextFileInputMeta info = new TextFileInputMeta();
    getInfo( info );

View on GitHub (pinned to f3058517a1)