{"record":{"id":"99762b5fb861bb3a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-num2str-requires-1-2-or-3-arguments","errorCode":null,"errorMessage":"The function call num2str requires 1, 2, or 3 arguments.","messagePattern":"The function call num2str requires 1, 2, or 3 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1359,"sourceCode":"            return (String) undefinedValue;\n          }\n          double sArg1 = (Double) ArgList[0];\n          if ( Double.isNaN( sArg1 ) ) {\n            throw new RuntimeException( \"The first Argument must be a Number.\" );\n          }\n          String sArg2 = (String) ArgList[1];\n          String sArg3 = (String) ArgList[2];\n          if ( sArg3.length() == 2 ) {\n            DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );\n            DecimalFormat formatter = new DecimalFormat( sArg2, dfs );\n            sRC = formatter.format( sArg1 );\n          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( e.toString() );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call num2str requires 1, 2, or 3 arguments.\" );\n    }\n\n    return sRC;\n  }\n\n  // Converts the given String to a JScript Numeric\n  public static Object str2num( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    double dRC = 0.00;\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"The function call str2num requires at least 1 argument.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return undefinedValue;","sourceCodeStart":1341,"sourceCodeEnd":1377,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1341-L1377","documentation":"Arity guard in the num2str script function: the JS/JSR-223 call site passed an unsupported number of arguments. num2str formats a number to a string using an optional DecimalFormat pattern (arg2) and optional 2-letter locale (arg3), so only the 1-, 2-, and 3-argument forms are valid; any other count reaches this else-branch and aborts the transformation.","triggerScenarios":"Calling num2str() with no arguments, or with 4+ arguments, inside a JavaScript/V Rhino script in the Kettle scripting step.","commonSituations":"Copy-paste errors leaving a stray argument; forgetting the number argument entirely; refactoring scripts where a variable became undefined and arguments.length collapsed to 0.","solutions":["Call num2str with exactly 1, 2, or 3 arguments.","Add a default for missing arguments: num2str(value || 0, pattern || \"#,##0.00\").","Check argument count in script before calling: if (arguments.length >= 1 && arguments.length <= 3)."],"exampleFix":"// before\nvar s = num2str(1234.5, \"#,##0.00\", \"en\", \"extra\");\n// after\nvar s = num2str(1234.5, \"#,##0.00\", \"en\");","handlingStrategy":"validation","validationCode":"if (arguments.length >= 1 && arguments.length <= 3) { var s = num2str.apply(null, arguments); }","typeGuard":null,"tryCatchPattern":"try { return num2str(v, p, loc); } catch (e) { if (String(e).indexOf(\"requires 1, 2, or 3 arguments\") >= 0) return \"\"; throw e; }","preventionTips":["Always call num2str with 1-3 arguments","Guard against undefined variables silently dropping arguments","Review refactored scripts for stray or missing parameters"],"tags":["argument-count","javascript-scripting","arity"],"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"}