pentaho/pentaho-kettle · error · RuntimeException

Error while reading file \"

Error message

Error while reading file \"

What it means

The loadScriptFile/addScriptFile helper failed with an IOException (or similar) while reading an additional JavaScript file and wraps it in a RuntimeException: 'Error while reading file "<fileName>" (reason: <cause>)'. It means the extra .js file could not be opened/read from the filesystem or classpath.

Solutions

  1. Verify the file exists and is readable at the exact path: ls -l /path/to/file.js.
  2. Use an absolute path or a path relative to the transformation's directory (and reference it via ${Internal.Transformation.Filename.Directory}).
  3. Fix permissions (chmod/chown) so the user running Pentaho/Kettle can read the file.
  4. Fix path separators for the target OS or use forward slashes which Java accepts cross-platform.

Example fix

// before
loadScriptFile('scripts\\helpers.js');
// after
loadScriptFile('${Internal.Transformation.Filename.Directory}/scripts/helpers.js');
Defensive patterns

Strategy: validation

Validate before calling

// in JS, guard before loadScriptFile
var f = new java.io.File(path);
if (!f.exists() || !f.canRead() || f.isDirectory()) throw new Error('Script file missing/unreadable: ' + path);
loadScriptFile(path);

Try / catch

try { loadScriptFile(path); } catch (e) { if (/Error while reading file/.test(e.message)) logError('Cannot read JS file: ' + e.message); else throw e; }

Prevention

When it happens

Trigger: Adding a supplementary JS file whose path does not exist, is a directory, lacks read permission, or whose stream cannot be read (disk I/O error) during script step initialization.

Common situations: Relative paths that resolve differently on the server vs the designer; file moved/deleted after the transformation was authored; permissions tightened on Linux deployments; using Windows-style paths on a Unix server.

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/809911bce8b7585c. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1735

  // Evaluates the given ScriptFile
  private static void checkAndLoadJSFile( Bowl bowl, ScriptEngine actualContext, Bindings eval_scope, String fileName ) {
    Reader inStream = null;
    try {
      inStream = new InputStreamReader( KettleVFS.getInstance( bowl ).getInputStream( fileName ) );
      actualContext.eval( inStream, eval_scope );
    } catch ( KettleFileException Signal ) {
      /*
       * //TODO AKRETION: see if we can find better catches compatibles with JSR223 catch (FileNotFoundException Signal)
       * { new RuntimeException("Unable to open file \"" + fileName + "\" (reason: \"" + Signal.getMessage() + "\")"); }
       * catch (WrappedException Signal) { new RuntimeException("WrappedException while evaluating file \"" + fileName +
       * "\" (reason: \"" + Signal.getMessage() + "\")"); } catch (EvaluatorException Signal) { new
       * RuntimeException("EvaluatorException while evaluating file \"" + fileName + "\" (reason: \"" +
       * Signal.getMessage() + "\")"); } catch (JavaScriptException Signal) { new
       * RuntimeException("JavaScriptException while evaluating file \"" + fileName + "\" (reason: \"" +
       * Signal.getMessage() + "\")"); } catch (IOException Signal) { new RuntimeException("Error while reading file \""
       * + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" ); }
       */
      throw new RuntimeException( "Error while reading file \""
        + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
    } catch ( ScriptException Signal ) {
      throw new RuntimeException( "Error while reading file \""
        + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
    } finally {
      try {
        if ( inStream != null ) {
          inStream.close();
        }
      } catch ( Exception Signal ) {
        // Ignore
      }
    }
  }

  // Setting Variable
  public static void setVariable( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {

View on GitHub (pinned to f3058517a1)