{"record":{"id":"eb0cb646309d832c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2num-requires-1-2-or-3-arguments-eb0cb6","errorCode":null,"errorMessage":"The function call str2num requires 1, 2, or 3 arguments.","messagePattern":"The function call str2num requires 1, 2, or 3 arguments\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1464,"sourceCode":"            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n            return Context.getUndefinedValue();\n          }\n          String sArg1 = Context.toString( ArgList[0] );\n          String sArg2 = Context.toString( ArgList[1] );\n          String sArg3 = Context.toString( ArgList[2] );\n          if ( sArg3.length() == 2 ) {\n            DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );\n            DecimalFormat formatter = new DecimalFormat( sArg2, dfs );\n            dRC = ( formatter.parse( sArg1 ) ).doubleValue();\n            return new Double( dRC );\n          }\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( e.getMessage() );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call str2num requires 1, 2, or 3 arguments.\" );\n    }\n    return new Double( dRC );\n  }\n\n  public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return Context.getUndefinedValue();\n        }\n        double sArg1 = Context.toNumber( ArgList[0] );\n        if ( Double.isNaN( sArg1 ) ) {\n          return Boolean.FALSE;\n        } else {","sourceCodeStart":1446,"sourceCodeEnd":1482,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1446-L1482","documentation":"The str2num JavaScript function only accepts 1, 2, or 3 arguments (value, optional format, optional locale). Calling it with zero or 4+ arguments falls into the switch's default case and throws this error via Context.reportRuntimeError. It is an argument-count validation error, not a data-conversion failure.","triggerScenarios":"str2num() with no arguments; str2num('123', '#,##0', 'en', extraArg); a scripting mistake spreading an array into the call; editing a shared script so extra positional params were added.","commonSituations":"Copy-pasted snippets in Modified Java Script Value steps where someone added a 4th parameter believing it was a rounding mode or currency flag; refactoring that lost or duplicated an argument.","solutions":["Call str2num with 1 argument for default parsing, 2 for pattern, 3 for pattern+locale","Remove any 4th+ argument from the call","Apply rounding or currency handling after str2num returns the Double","Check the JavaScript step's script for array-spread or auto-fill mistakes"],"exampleFix":"// before\nvar n = str2num('123.45', '#,##0.00', 'en', 2); // 4 args -> error\n// after\nvar n = str2num('123.45', '#,##0.00', 'en');","handlingStrategy":"validation","validationCode":"function str2numChecked() {\n  var a = Array.prototype.slice.call(arguments);\n  if (a.length < 1 || a.length > 3) {\n    throw new Error('str2num requires 1-3 arguments, got ' + a.length);\n  }\n  return str2num.apply(null, a);\n}","typeGuard":"function canCallStr2num(args) { return args.length >= 1 && args.length <= 3; }","tryCatchPattern":"try {\n  var n = str2num(value, fmt);\n} catch (e) {\n  if (e.message.indexOf('requires 1, 2, or 3 arguments') >= 0) {\n    // arity bug in the script — fix the call site, don't retry\n    throw new Error('Script bug: bad str2num call arity');\n  }\n  throw e;\n}","preventionTips":["Count arguments at the call site when editing shared scripts","Don't invent extra parameters (currency, rounding) — str2num has no such overloads","Wrap arity-checked helpers around str2num in team scripts","Review script diffs in the JavaScript step before running transformations"],"tags":["javascript","argument-count","pentaho","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"}