pentaho/pentaho-kettle · error · JavaScriptException

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

Validation guard in ScriptValuesAddedFunctions.date2str, which formats a Date to a String using an optional format and locale. It fires when the first argument cannot be resolved to a valid Date (null, undefined, or a non-date value passed as the date to format), so the function aborts with a Rhino runtime error rather than formatting garbage. Fix by passing an actual java.util.Date (e.g. from str2date or a Date-typed field) as the first argument.

Solutions

  1. Pass a date as the first argument, e.g. date2str(new Date())
  2. Add an output format pattern (and optionally locale/timezone) as further arguments
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1126 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/7603dec52de93830. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1126

        } catch ( Exception e ) {
          throw Context
            .reportRuntimeError( "Could not apply the local format for locale "
              + sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : "
              + e.getMessage() );
        }
        break;
      default:
        throw Context.reportRuntimeError( "The function call str2date requires 1, 2, 3, or 4 arguments." );
    }
    return oRC;
  }

  public static Object date2str( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    Object oRC = new Object();
    switch ( ArgList.length ) {
      case 0:
        throw Context.reportRuntimeError( "Please provide a valid date to the function call date2str." );
      case 1:
        try {
          if ( isNull( ArgList ) ) {
            return null;
          } else if ( isUndefined( ArgList ) ) {
            return Context.getUndefinedValue();
          }
          java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
          if ( dArg1.equals( null ) ) {
            return null;
          }
          Format dfFormatter = new SimpleDateFormat();
          oRC = dfFormatter.format( dArg1 );
        } catch ( Exception e ) {
          throw Context.reportRuntimeError( "Could not convert to local format." );
        }
        break;
      case 2:

View on GitHub (pinned to f3058517a1)