{"record":{"id":"3ed458b763c3bd14","repo":"pentaho/pentaho-kettle","slug":"the-function-call-date2str-requires-1-2-3-or-4-arguments-3ed458","errorCode":null,"errorMessage":"The function call date2str requires 1, 2, 3, or 4 arguments.","messagePattern":"The function call date2str requires 1, 2, 3, or 4 arguments\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1211,"sourceCode":"\n          // If the timezone is not recognized, java will automatically\n          // take GMT.\n          TimeZone tz = TimeZone.getTimeZone( sArg4 );\n\n          if ( sArg3.length() == 2 ) {\n            Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );\n            dfFormatter = new SimpleDateFormat( sArg2, dfLocale );\n            dfFormatter.setTimeZone( tz );\n            oRC = dfFormatter.format( dArg1 );\n          } else {\n            throw Context.reportRuntimeError( \"Locale is not 2 characters long.\" );\n          }\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( \"Could not convert to the given local format.\" );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call date2str requires 1, 2, 3, or 4 arguments.\" );\n    }\n    return oRC;\n  }\n\n  public static Object isRegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    if ( ArgList.length >= 2 ) {\n      if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n        return null;\n      } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n        return Context.getUndefinedValue();\n      }\n      String strToMatch = Context.toString( ArgList[0] );\n      for ( int i = 1; i < ArgList.length; i++ ) {\n        Pattern p = Pattern.compile( Context.toString( ArgList[i] ) );\n        Matcher m = p.matcher( strToMatch );\n        if ( m.matches() ) {","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1193-L1229","documentation":"Thrown by date2str when it is called with more than 4 (or, in the default branch, any unsupported) argument count. The function's switch dispatches on ArgList.length for 1–4 arguments and falls through to default otherwise, immediately raising this runtime error listing the accepted arities. It is a strict arity check, not a type error.","triggerScenarios":"Calling date2str() with 0 arguments or with 5+ arguments, e.g. date2str(d, fmt, loc, tz, extra), commonly from an accidental leftover parameter or a spread that expands too far.","commonSituations":"Refactoring a script that added an extra format argument; programmatically building argument arrays (apply) that include trailing nulls/undefined entries which still count toward length; combining two variants of the call during merge.","solutions":["Count the arguments: keep the call to 1, 2, 3, or 4 parameters.","Remove extra trailing arguments or nulls from the call/argument array.","If you need more control, perform formatting in a User Defined Java Class step instead of extending date2str's signature.","Wrap the call in a small helper that slices ArgList to at most 4 items."],"exampleFix":"// before\ndate2str(d, fmt, loc, tz, extraArg)\n// after\ndate2str(d, fmt, loc, tz)","handlingStrategy":"validation","validationCode":"// JS\nvar args = [d, fmt, loc, tz].filter(function(x){ return x !== undefined; }).slice(0, 4);\nvar s = date2str.apply(null, args);","typeGuard":"function hasValidDate2strArity(a) { return a.length >= 1 && a.length <= 4; }","tryCatchPattern":"try { s = date2str(d, fmt, loc, tz); } catch (e) { if (String(e).indexOf(\"1, 2, 3, or 4\") >= 0) s = null; else throw e; }","preventionTips":["Never pass more than 4 arguments to date2str","Filter undefined entries before applying argument arrays","Call with exactly the variant you need","At least one argument (the date) is mandatory"],"tags":["javascript","argument-count","pentaho-kettle"],"backgroundTag":"missing-required-argument","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"}