{"record":{"id":"471cb3a434fb1373","repo":"pentaho/pentaho-kettle","slug":"the-function-call-appendtofile-requires-arguments","errorCode":null,"errorMessage":"The function call appendToFile requires arguments.","messagePattern":"The function call appendToFile requires arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":206,"sourceCode":"      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static void appendToFile( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {\n      try {\n        FileOutputStream file = new FileOutputStream( (String) ArgList[0], true );\n        DataOutputStream out = new DataOutputStream( file );\n        out.writeBytes( (String) ArgList[1] );\n        out.flush();\n        out.close();\n      } catch ( Exception er ) {\n        throw new RuntimeException( er.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call appendToFile requires arguments.\" );\n    }\n  }\n\n  public static Object getFiscalDate( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList ) ) {\n          return null;\n        } else if ( isUndefined( ArgList ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dIn = (java.util.Date) ArgList[0];\n        Calendar startDate = Calendar.getInstance();\n        Calendar fisStartDate = Calendar.getInstance();\n        Calendar fisOffsetDate = Calendar.getInstance();\n        startDate.setTime( dIn );","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L188-L224","documentation":"Arity guard in ScriptAddedFunctions.appendToFile: the script invoked the function with a null/undefined or empty argument list, but it needs (filename, content) to open the FileOutputStream in append mode and write the bytes. The guard fires before any file is touched.","triggerScenarios":"Calling appendToFile() with no arguments from a Script step; a variable holding the content being undefined so the dynamically-built argument list is empty.","commonSituations":"Logging scripts where the message variable is undefined/null and got dropped; generated scripts with conditional argument construction that skipped all args.","solutions":["Pass the filename (and content) explicitly: appendToFile(filename, content)","Guard undefined variables in JS before the call","Wrap in try/catch and fall back to a default message"],"exampleFix":"// before\nappendToFile();\n// after\nappendToFile('/tmp/out.log', 'entry: ' + value);","handlingStrategy":"validation","validationCode":"// JS in Script step\nif (arguments.length === 0) {\n  throw new Error('appendToFile needs at least a filename');\n}\nappendToFile(filename, content);","typeGuard":"// JS\nfunction hasArgs(args) {\n  return args.length > 0;\n}","tryCatchPattern":"try {\n  appendToFile(file, msg);\n} catch (e) {\n  Logger.logError('appendToFile failed: ' + e.message);\n}","preventionTips":["Never build argument arrays conditionally such that they can end up empty","Default-define file/content variables at the top of the script","Check for undefined variables before calls"],"tags":["kettle","javascript","arity","file-io"],"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"}