pentaho/pentaho-kettle · error · RuntimeException
The function call date2str requires 1, 2, 3, or 4 arguments.
Error message
The function call date2str requires 1, 2, 3, or 4 arguments.
What it means
Thrown by date2str() when it is called with more than 4 arguments; the function's switch only handles signatures with 1 to 4 arguments (date, [format], [locale], [timezone]) and the default branch rejects anything else.
Solutions
- Remove extra arguments; use at most 4: date, format, locale, timezone.
- If you need custom behavior beyond the 4 supported parameters, format in two steps or use a User Defined Java Expression / UDF.
Example fix
// before date2str(d, 'yyyy-MM-dd', 'en', 'UTC', 'extra') // after date2str(d, 'yyyy-MM-dd', 'en', 'UTC')
Defensive patterns
Strategy: validation
Validate before calling
function safeDate2str() {
var args = Array.prototype.slice.call(arguments);
if (args.length > 4) args = args.slice(0, 4);
if (args.length < 1) throw new Error('date2str needs a date');
return date2str.apply(null, args);
} Try / catch
try { return date2str(d, fmt, loc, tz); }
catch (e) { if (/requires 1, 2, 3, or 4/.test(e.message)) return date2str(d); throw e; } Prevention
- Remember the maximum signature: date, format, locale, timezone.
- Never pass cc-style extra parameters hoping they are ignored.
- Use the Mail or Java-filter steps for features beyond the 4 supported args.
When it happens
Trigger: Invoking date2str with 5+ arguments in a Script step, e.g. date2str(d, fmt, loc, tz, extra).
Common situations: Copy-pasted JavaScript from another environment (native JS Date formatting habits), or mistakenly appending extra parameters expecting them to be ignored like in some JS engines.
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
- Please provide a valid date to the function call date2str.
- The function call lower requires 1 argument.
- The function call num2str requires at least 1 argument.
- The function call upper requires 1 argument.
- Could not convert to local format.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/69e197aa436a6ff8.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1177
// If the timezone is not recognized, java will automatically
// take GMT.
TimeZone tz = TimeZone.getTimeZone( sArg4 );
if ( sArg3.length() == 2 ) {
Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );
dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
dfFormatter.setTimeZone( tz );
oRC = dfFormatter.format( dArg1 );
} else {
throw new RuntimeException( "Locale is not 2 characters long." );
}
} catch ( Exception e ) {
throw new RuntimeException( "Could not convert to the given local format." );
}
break;
default:
throw new RuntimeException( "The function call date2str requires 1, 2, 3, or 4 arguments." );
}
return oRC;
}
public static Object isRegExp( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
if ( ArgList.length >= 2 ) {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return undefinedValue;
}
String strToMatch = (String) ArgList[0];
for ( int i = 1; i < ArgList.length; i++ ) {
Pattern p = Pattern.compile( (String) ArgList[i] );
Matcher m = p.matcher( strToMatch );
if ( m.matches() ) {View on GitHub (pinned to f3058517a1)