pentaho/pentaho-kettle · error · RhinoRuntimeError
The function call str2num requires at least 1 argument.
Error message
The function call str2num requires at least 1 argument.
What it means
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.
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.
Example fix
// before var n = str2num(); // after var n = str2num(amountText);
Defensive patterns
Strategy: validation
Validate before calling
function safeStr2num(s) {
if (s === null || s === undefined || s === '') return NaN;
return str2num(s);
} Type guard
function isStringArg(v) { return typeof v === 'string'; } Prevention
- Always pass the string to parse as the first argument.
- Check call sites after refactoring for lost arguments.
- Guard against empty values before parsing.
When it happens
Trigger: Calling str2num() with no arguments in a Modified Java Script Value step: e.g. `var n = str2num();`.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Could not convert the given String :
- The function call dateAdd requires 3 arguments.
- The function call dateDiff requires 3 arguments.
- The function call fillString requires 2 arguments.
- The function call fireToDB requires 2 arguments.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/59a90431b0caccc5.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1405
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
break;
default:
throw Context.reportRuntimeError( "The function call num2str requires 1, 2, or 3 arguments." );
}
return sRC;
}
// Converts the given String to a JScript Numeric
public static Object str2num( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
double dRC = 0.00;
switch ( ArgList.length ) {
case 0:
throw Context.reportRuntimeError( "The function call str2num requires at least 1 argument." );
case 1:
try {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
if ( ArgList[0].equals( null ) ) {
return null;
}
String sArg1 = Context.toString( ArgList[0] );
DecimalFormat formatter = new DecimalFormat();
dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();
} catch ( Exception e ) {
throw Context.reportRuntimeError( "Could not convert the given String : " + e.getMessage() );
}
break;
case 2:View on GitHub (pinned to f3058517a1)