{"record":{"id":"59a90431b0caccc5","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2num-requires-at-least-1-argument-59a904","errorCode":null,"errorMessage":"The function call str2num requires at least 1 argument.","messagePattern":"The function call str2num requires at least 1 argument\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1405,"sourceCode":"          }\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( e.toString() );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"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( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    double dRC = 0.00;\n    switch ( ArgList.length ) {\n      case 0:\n        throw Context.reportRuntimeError( \"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 Context.getUndefinedValue();\n          }\n          if ( ArgList[0].equals( null ) ) {\n            return null;\n          }\n          String sArg1 = Context.toString( ArgList[0] );\n          DecimalFormat formatter = new DecimalFormat();\n          dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( \"Could not convert the given String : \" + e.getMessage() );\n        }\n        break;\n      case 2:","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1387-L1423","documentation":"The str2num JavaScript function parses a string into a numeric value using DecimalFormat. It requires at least one argument; a zero-argument call throws this Rhino runtime error immediately from the switch's case 0.","triggerScenarios":"Calling str2num() with no arguments in a Modified Java Script Value step: e.g. `var n = str2num();`.","commonSituations":"Dropped argument during copy-paste; assuming str2num parses a field implicitly like some spreadsheet functions; variable name typo leaving an empty call; refactoring that removed the argument but kept the call.","solutions":["Pass the string to parse as the first argument: str2num(myStringField).","Verify the call site — the argument must be a string parseable by the default DecimalFormat.","If the value may be missing, guard the call site before invoking str2num."],"exampleFix":"// before\nvar n = str2num();\n\n// after\nvar n = str2num(amountText);","handlingStrategy":"validation","validationCode":"function safeStr2num(s) {\n  if (s === null || s === undefined || s === '') return NaN;\n  return str2num(s);\n}","typeGuard":"function isStringArg(v) { return typeof v === 'string'; }","tryCatchPattern":null,"preventionTips":["Always pass the string to parse as the first argument.","Check call sites after refactoring for lost arguments.","Guard against empty values before parsing."],"tags":["javascript","kettle","argument-count","parsing"],"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"}