{"record":{"id":"809911bce8b7585c","repo":"pentaho/pentaho-kettle","slug":"error-while-reading-file","errorCode":null,"errorMessage":"Error while reading file \\\"","messagePattern":"Error while reading file \\\\\"","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1735,"sourceCode":"  // Evaluates the given ScriptFile\n  private static void checkAndLoadJSFile( Bowl bowl, ScriptEngine actualContext, Bindings eval_scope, String fileName ) {\n    Reader inStream = null;\n    try {\n      inStream = new InputStreamReader( KettleVFS.getInstance( bowl ).getInputStream( fileName ) );\n      actualContext.eval( inStream, eval_scope );\n    } catch ( KettleFileException Signal ) {\n      /*\n       * //TODO AKRETION: see if we can find better catches compatibles with JSR223 catch (FileNotFoundException Signal)\n       * { new RuntimeException(\"Unable to open file \\\"\" + fileName + \"\\\" (reason: \\\"\" + Signal.getMessage() + \"\\\")\"); }\n       * catch (WrappedException Signal) { new RuntimeException(\"WrappedException while evaluating file \\\"\" + fileName +\n       * \"\\\" (reason: \\\"\" + Signal.getMessage() + \"\\\")\"); } catch (EvaluatorException Signal) { new\n       * RuntimeException(\"EvaluatorException while evaluating file \\\"\" + fileName + \"\\\" (reason: \\\"\" +\n       * Signal.getMessage() + \"\\\")\"); } catch (JavaScriptException Signal) { new\n       * RuntimeException(\"JavaScriptException while evaluating file \\\"\" + fileName + \"\\\" (reason: \\\"\" +\n       * Signal.getMessage() + \"\\\")\"); } catch (IOException Signal) { new RuntimeException(\"Error while reading file \\\"\"\n       * + fileName + \"\\\" (reason: \\\"\" + Signal.getMessage() + \"\\\")\" ); }\n       */\n      throw new RuntimeException( \"Error while reading file \\\"\"\n        + fileName + \"\\\" (reason: \\\"\" + Signal.getMessage() + \"\\\")\" );\n    } catch ( ScriptException Signal ) {\n      throw new RuntimeException( \"Error while reading file \\\"\"\n        + fileName + \"\\\" (reason: \\\"\" + Signal.getMessage() + \"\\\")\" );\n    } finally {\n      try {\n        if ( inStream != null ) {\n          inStream.close();\n        }\n      } catch ( Exception Signal ) {\n        // Ignore\n      }\n    }\n  }\n\n  // Setting Variable\n  public static void setVariable( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1717-L1753","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the file exists and is readable at the exact path: ls -l /path/to/file.js.","Use an absolute path or a path relative to the transformation's directory (and reference it via ${Internal.Transformation.Filename.Directory}).","Fix permissions (chmod/chown) so the user running Pentaho/Kettle can read the file.","Fix path separators for the target OS or use forward slashes which Java accepts cross-platform."],"exampleFix":"// before\nloadScriptFile('scripts\\\\helpers.js');\n// after\nloadScriptFile('${Internal.Transformation.Filename.Directory}/scripts/helpers.js');","handlingStrategy":"validation","validationCode":"// in JS, guard before loadScriptFile\nvar f = new java.io.File(path);\nif (!f.exists() || !f.canRead() || f.isDirectory()) throw new Error('Script file missing/unreadable: ' + path);\nloadScriptFile(path);","typeGuard":null,"tryCatchPattern":"try { loadScriptFile(path); } catch (e) { if (/Error while reading file/.test(e.message)) logError('Cannot read JS file: ' + e.message); else throw e; }","preventionTips":["Use absolute paths or ${Internal.Transformation.Filename.Directory}.","Verify existence/permissions on every server the transformation runs on.","Avoid OS-specific path separators; use forward slashes.","Keep shared JS files under version control next to the transformation."],"tags":["javascript","file-io","file-not-found","script-step"],"backgroundTag":"file-read-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}