{"record":{"id":"7e431f3310713f02","repo":"pentaho/pentaho-kettle","slug":"please-provide-a-filename-to-the-function-call","errorCode":null,"errorMessage":"Please provide a filename to the function call loadFileContent.","messagePattern":"Please provide a filename to the function call loadFileContent\\.","errorType":"exception","errorClass":"Rhino runtime error","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2792,"sourceCode":"\n  public static String initCap( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.initCap( Context.toString( ArgList[0] ) );\n    } else {\n      throw Context.reportRuntimeError( \"The function call initCap requires 1 argument.\" );\n\n    }\n  }\n\n  public static Object loadFileContent( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    Object oRC = new Object();\n    try {\n\n      switch ( ArgList.length ) {\n        case 0:\n          throw Context.reportRuntimeError( \"Please provide a filename to the function call loadFileContent.\" );\n        case 1:\n          try {\n            if ( isNull( ArgList ) ) {\n              return null;\n            } else if ( isUndefined( ArgList ) ) {\n              return Context.getUndefinedValue();\n            }\n            // Returns file content\n            oRC = new String( LoadFileInput.getFileBinaryContent( getBowl( actualObject ),\n                                                                  Context.toString( ArgList[0] ) ) );\n          } catch ( Exception e ) {\n            throw Context\n              .reportRuntimeError( \"The function call loadFileContent throw an error : \" + e.toString() );\n          }\n          break;\n        case 2:\n          try {\n            if ( ArgList[0].equals( null ) ) {","sourceCodeStart":2774,"sourceCodeEnd":2810,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2774-L2810","documentation":"loadFileContent reads a file's contents into a JS variable in the Modified Java Script Value step. The library throws this Rhino runtime error when the function is called with zero arguments, because a filename is mandatory to know which file to read.","triggerScenarios":"loadFileContent() with an empty argument list — the switch case 0 immediately throws Context.reportRuntimeError; also occurs when the filename variable passed is dropped so the array is empty.","commonSituations":"Field variable undefined at runtime so the call collapses to no arguments; users forgetting to pass the path expecting a file-picker dialog; scripts copied without the filename argument.","solutions":["Pass the file path as the first argument: loadFileContent('/path/to/file')","Ensure the filename variable is non-empty before calling (guard with an if)","Check that the field feeding the argument is populated in the incoming rows","Prefer Kettle's Text File Input step for bulk file reads instead of per-row JS"],"exampleFix":"// before\nvar content = loadFileContent();\n// after\nvar content = loadFileContent(filenameField);","handlingStrategy":"validation","validationCode":"if (typeof filenameField === 'string' && filenameField.length > 0) { var content = loadFileContent(filenameField); } else { var content = null; }","typeGuard":"function hasFilename(v){ return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try { var content = loadFileContent(filenameField); } catch (e) { throw new Error('loadFileContent needs a filename: ' + e.message); }","preventionTips":["Always pass a non-empty filename as the first argument","Validate the incoming field is populated before calling","Use dedicated input steps for heavy file reading rather than per-row JS","Handle null/undefined filename rows gracefully instead of letting the call collapse to zero args"],"tags":["javascript","file-io","missing-argument","pentaho-kettle"],"backgroundTag":"missing-required-argument","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"}