pentaho/pentaho-kettle · error · RhinoRuntimeError
The function call str2num requires 1, 2, or 3 arguments.
Error message
The function call str2num requires 1, 2, or 3 arguments.
What it means
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.
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
Example fix
// before
var n = str2num('123.45', '#,##0.00', 'en', 2); // 4 args -> error
// after
var n = str2num('123.45', '#,##0.00', 'en'); Defensive patterns
Strategy: validation
Validate before calling
function str2numChecked() {
var a = Array.prototype.slice.call(arguments);
if (a.length < 1 || a.length > 3) {
throw new Error('str2num requires 1-3 arguments, got ' + a.length);
}
return str2num.apply(null, a);
} Type guard
function canCallStr2num(args) { return args.length >= 1 && args.length <= 3; } Try / catch
try {
var n = str2num(value, fmt);
} catch (e) {
if (e.message.indexOf('requires 1, 2, or 3 arguments') >= 0) {
// arity bug in the script — fix the call site, don't retry
throw new Error('Script bug: bad str2num call arity');
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- The function call decode requires more than 1 argument.
- The function call replace is not valid (wrong number of…
- Function call replace is not valid :
- Please provide a valid date to the function call date2str.
- Row.EndOfFileReached
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/eb0cb646309d832c.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1464
return new Double( Double.NaN );
} else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
return Context.getUndefinedValue();
}
String sArg1 = Context.toString( ArgList[0] );
String sArg2 = Context.toString( ArgList[1] );
String sArg3 = Context.toString( ArgList[2] );
if ( sArg3.length() == 2 ) {
DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );
DecimalFormat formatter = new DecimalFormat( sArg2, dfs );
dRC = ( formatter.parse( sArg1 ) ).doubleValue();
return new Double( dRC );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.getMessage() );
}
break;
default:
throw Context.reportRuntimeError( "The function call str2num requires 1, 2, or 3 arguments." );
}
return new Double( dRC );
}
public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
double sArg1 = Context.toNumber( ArgList[0] );
if ( Double.isNaN( sArg1 ) ) {
return Boolean.FALSE;
} else {View on GitHub (pinned to f3058517a1)