{"record":{"id":"c3492e4e8e5377bf","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2num-requires-1-2-or-3-arguments","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":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1429,"sourceCode":"            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n            return undefinedValue;\n          }\n          String sArg1 = (String) ArgList[0];\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            dRC = ( formatter.parse( sArg1 ) ).doubleValue();\n            return new Double( dRC );\n          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( e.getMessage() );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call str2num requires 1, 2, or 3 arguments.\" );\n    }\n    return new Double( dRC );\n  }\n\n  public static Object isNum( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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 undefinedValue;\n        }\n        double sArg1 = (Double) ArgList[0];\n        if ( Double.isNaN( sArg1 ) ) {\n          return Boolean.FALSE;\n        } else {","sourceCodeStart":1411,"sourceCodeEnd":1447,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1411-L1447","documentation":"str2num only supports 1, 2, or 3 arguments (value, optional pattern, optional locale). If the JS script calls it with zero arguments or more than three, the switch falls to the default branch and this RuntimeException is thrown to fail the transformation step.","triggerScenarios":"Calling str2num() with no arguments, or str2num(a, b, c, d) with four or more arguments from a JavaScript step.","commonSituations":"Refactoring scripts and leaving stale arguments, passing an array without spreading it, copy-paste errors between differently-arity helper functions.","solutions":["Call str2num with exactly 1-3 arguments: str2num(value) or str2num(value, pattern) or str2num(value, pattern, locale).","Check the call site in your JavaScript step for extra/missing arguments.","If you need more options, do the parsing manually with java.text.DecimalFormat in the script."],"exampleFix":"// before\nvar n = str2num(value, '#,##0.00', 'en', true); // 4 args -> throws\n// after\nvar n = str2num(value, '#,##0.00', 'en');","handlingStrategy":"validation","validationCode":"function safeStr2num() {\n  if (arguments.length < 1 || arguments.length > 3) {\n    throw new Error('str2num requires 1, 2, or 3 arguments');\n  }\n  return str2num.apply(null, arguments);\n}","typeGuard":null,"tryCatchPattern":"try {\n  var n = str2num(v, pattern, locale);\n} catch (e) {\n  if (String(e.message).indexOf('requires 1, 2, or 3') >= 0) {\n    // fix arity at call site / alert developer\n  }\n}","preventionTips":["Never pass more than 3 arguments to str2num.","Always pass at least the value argument.","Spread arrays explicitly rather than passing an array object."],"tags":["java","pdi","scripting","argument-count"],"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"}