{"record":{"id":"7603dec52de93830","repo":"pentaho/pentaho-kettle","slug":"please-provide-a-valid-date-to-the-function-call-date2str-7603de","errorCode":null,"errorMessage":"Please provide a valid date to the function call date2str.","messagePattern":"Please provide a valid date to the function call date2str\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1126,"sourceCode":"        } catch ( Exception e ) {\n          throw Context\n            .reportRuntimeError( \"Could not apply the local format for locale \"\n              + sArg3 + \" with the given format \" + sArg2 + \" on the string for \" + sArg1 + \" : \"\n              + e.getMessage() );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call str2date requires 1, 2, 3, or 4 arguments.\" );\n    }\n    return oRC;\n  }\n\n  public static Object date2str( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    Object oRC = new Object();\n    switch ( ArgList.length ) {\n      case 0:\n        throw Context.reportRuntimeError( \"Please provide a valid date to the function call date2str.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList ) ) {\n            return null;\n          } else if ( isUndefined( ArgList ) ) {\n            return Context.getUndefinedValue();\n          }\n          java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n          if ( dArg1.equals( null ) ) {\n            return null;\n          }\n          Format dfFormatter = new SimpleDateFormat();\n          oRC = dfFormatter.format( dArg1 );\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( \"Could not convert to local format.\" );\n        }\n        break;\n      case 2:","sourceCodeStart":1108,"sourceCodeEnd":1144,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1108-L1144","documentation":"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.","triggerScenarios":"Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1126 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a date as the first argument, e.g. date2str(new Date())","Add an output format pattern (and optionally locale/timezone) as further arguments"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}