{"record":{"id":"159cef99874e3196","repo":"pentaho/pentaho-kettle","slug":"the-function-call-writetolog-requires-1-or-2-arguments","errorCode":null,"errorMessage":"The function call writeToLog requires 1 or 2 arguments.","messagePattern":"The function call writeToLog requires 1 or 2 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":320,"sourceCode":"              scm.logBasic( strMessage );\n            } else if ( strType.equals( \"d\" ) ) {\n              scm.logDebug( strMessage );\n            } else if ( strType.equals( \"l\" ) ) {\n              scm.logDetailed( strMessage );\n            } else if ( strType.equals( \"e\" ) ) {\n              scm.logError( strMessage );\n            } else if ( strType.equals( \"m\" ) ) {\n              scm.logMinimal( strMessage );\n            } else if ( strType.equals( \"r\" ) ) {\n              scm.logRowlevel( strMessage );\n            }\n          }\n        } catch ( Exception e ) {\n          // Ignore errors\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call writeToLog requires 1 or 2 arguments.\" );\n    }\n  }\n\n  private static boolean isUndefined( Object ArgList ) {\n    return isUndefined( new Object[] { ArgList }, new int[] { 0 } );\n  }\n\n  private static boolean isUndefined( Object[] ArgList, int[] iArrToCheck ) {\n    for ( int i = 0; i < iArrToCheck.length; i++ ) {\n      if ( ArgList[iArrToCheck[i]].equals( undefinedValue ) ) {\n        return true;\n      }\n    }\n    return false;\n  }\n\n  private static boolean isNull( Object ArgList ) {\n    return isNull( new Object[] { ArgList }, new int[] { 0 } );","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L302-L338","documentation":"writeToLog writes to the transformation log and accepts 1 argument (message, default log level) or 2 arguments (log level, message). A switch over ArgList.length falls through to default and throws RuntimeException for any other count.","triggerScenarios":"Calling writeToLog() with zero arguments or with 3+ arguments, e.g. writeToLog(level, msg, detail) in a Script step.","commonSituations":"Passing varargs messages (writeToLog('a', 'b', 'c')); forgetting to concatenate message parts; porting from log4j-style calls with throwable argument.","solutions":["Combine message parts into one string: writeToLog('l', msg1 + msg2)","Use the 1-arg form writeToLog(msg) when default level is fine","Never pass a throwable; format it into the message"],"exampleFix":"// before\nwriteToLog(LogWriter.LOG_LEVEL_BASIC, 'x=', value, ' y=', other);\n// after\nwriteToLog(LogWriter.LOG_LEVEL_BASIC, 'x=' + value + ' y=' + other);","handlingStrategy":"validation","validationCode":"// JS in Script step\nif (arguments.length < 1 || arguments.length > 2) {\n  throw new Error('writeToLog expects (msg) or (level, msg)');\n}\nwriteToLog(level, msg);","typeGuard":"// JS\nfunction validWriteToLogArgs(args) {\n  return args.length === 1 || args.length === 2;\n}","tryCatchPattern":"try {\n  writeToLog(LogWriter.LOG_LEVEL_BASIC, msg);\n} catch (e) {\n  // logging failed - fail safe, do not kill the transformation\n}","preventionTips":["Concatenate all message fragments into one string","Match 1-arg (message only) or 2-arg (level, message) forms exactly","Never pass exceptions/throwables directly; format them first"],"tags":["kettle","javascript","arity","logging"],"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"}