{"record":{"id":"d95c14bdb5aebfbb","repo":"pentaho/pentaho-kettle","slug":"the-function-call-num2str-requires-at-least-1-argument-d95c14","errorCode":null,"errorMessage":"The function call num2str requires at least 1 argument.","messagePattern":"The function call num2str requires at least 1 argument\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1334,"sourceCode":"        }\n        sRC = Context.toString( ArgList[0] );\n        sRC = sRC.toLowerCase();\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"The function call lower is not valid : \" + e.getMessage() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call lower requires 1 argument.\" );\n    }\n    return sRC;\n  }\n\n  // Converts the given Numeric to a JScript String\n  public static String num2str( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String sRC = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw Context.reportRuntimeError( \"The function call num2str requires at least 1 argument.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return null;\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return (String) Context.getUndefinedValue();\n          }\n          double sArg1 = Context.toNumber( ArgList[0] );\n          if ( Double.isNaN( sArg1 ) ) {\n            throw Context.reportRuntimeError( \"The first Argument must be a Number.\" );\n          }\n          DecimalFormat formatter = new DecimalFormat();\n          sRC = formatter.format( sArg1 );\n        } catch ( IllegalArgumentException e ) {\n          throw Context.reportRuntimeError( \"Could not apply the given format on the number : \" + e.getMessage() );\n        }\n        break;\n      case 2:","sourceCodeStart":1316,"sourceCodeEnd":1352,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1316-L1352","documentation":"The num2str JavaScript function (registered by ScriptValuesAddedFunctions for the Modified Java Script Value step) converts a numeric value to a formatted string. It requires at least one argument; when called with zero arguments, it throws this Rhino runtime error via Context.reportRuntimeError. The library enforces the 1-3 argument arity contract of num2str.","triggerScenarios":"Calling num2str() with no arguments in a JavaScript step script: e.g. `var s = num2str();`. ArgList.length == 0 hits `case 0` of the switch and throws immediately.","commonSituations":"Typos where the argument was dropped during edit; copy-paste of num2str from examples without replacing the placeholder; calling the function before the variable holding the number was assigned and assuming a default; porting scripts where a variable name was lost.","solutions":["Pass the number to format as the first argument: num2str(myNumericField).","Check the script for the call site and ensure the field/variable actually exists in the step's input rows.","If the value may be null/undefined, guard before calling: only call num2str when the value is not null."],"exampleFix":"// before\nvar s = num2str();\n\n// after\nvar s = num2str(price); // price is a numeric field from the incoming row","handlingStrategy":"validation","validationCode":"function safeNum2str(v) {\n  if (v === null || v === undefined) return null;\n  return num2str(v);\n}","typeGuard":"function isNumericArg(v) { return v !== null && v !== undefined && !isNaN(Number(v)); }","tryCatchPattern":null,"preventionTips":["Always supply at least the numeric value when calling num2str.","Review scripts after copy-paste for dropped arguments.","Centralize formatting in a small helper used across the transformation."],"tags":["javascript","kettle","argument-count","scripting"],"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"}