pentaho/pentaho-kettle · error · RuntimeException
Please provide a valid date to the function call date2str.
Error message
Please provide a valid date to the function call date2str.
What it means
date2str converts a java.util.Date to a string, and the first (only required) argument must be a date. Calling it with zero arguments hits case 0 of the switch and throws this RuntimeException telling you a valid date is required.
Solutions
- Pass a java.util.Date as the first argument, e.g. date2str(new Date()).
- Verify the variable holding the date is actually populated at call time.
- If the date may be absent, guard before calling: if (dateVar != null) date2str(dateVar).
- Remember format/locale/timezone are optional (args 2-4); only the date is required.
Example fix
// before var s = date2str(); // after var s = date2str(new Date());
Defensive patterns
Strategy: validation
Validate before calling
if (dateVar == null) throw new Error('date2str requires a date argument');
var s = date2str(dateVar); Type guard
function isDateLike(v) { return v != null && v.getClass && /Date/.test(String(v.getClass())); } Try / catch
try { var s = date2str(d); } catch (e) { if (String(e.message).indexOf('Please provide a valid date') >= 0) { throw new Error('date argument missing/undefined at call site'); } throw e; } Prevention
- Always pass the date as the first argument
- Check the date variable is populated before calling (null check)
- Convert strings/timestamps to Date via str2date() first
- Remember only the date is required; format/locale/timezone are optional
When it happens
Trigger: Invoking date2str() with no arguments in a JavaScript script step; the switch's case 0 unconditionally throws before any null-handling runs.
Common situations: Copy/paste mistakes leaving off the date argument; a variable that was expected to hold the date being undefined so the call collapses to date2str(); misunderstanding that the date is mandatory while format/locale/timezone are optional.
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 to local format.
- Could not convert to the given format.
- Could not convert to the given local format.
- Could not convert to the given local format.
- Locale is not 2 characters long.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/8a3543dfad2f8869.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1092
throw new RuntimeException( "Locale " + sArg3 + " is not 2 characters long." );
}
} catch ( Exception e ) {
throw new RuntimeException( "Could not apply the local format for locale "
+ sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage() );
}
break;
default:
throw new RuntimeException( "The function call str2date requires 1, 2, 3, or 4 arguments." );
}
return oRC;
}
public static Object date2str( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
Object oRC = new Object();
switch ( ArgList.length ) {
case 0:
throw new RuntimeException( "Please provide a valid date to the function call date2str." );
case 1:
try {
if ( isNull( ArgList ) ) {
return null;
} else if ( isUndefined( ArgList ) ) {
return undefinedValue;
}
java.util.Date dArg1 = (java.util.Date) ArgList[0];
if ( dArg1.equals( null ) ) {
return null;
}
Format dfFormatter = new SimpleDateFormat();
oRC = dfFormatter.format( dArg1 );
} catch ( Exception e ) {
throw new RuntimeException( "Could not convert to local format." );
}
break;
case 2:View on GitHub (pinned to f3058517a1)