pentaho/pentaho-kettle · error · RuntimeException

The function call week requires 1 argument.

Error message

The function call week requires 1 argument.

What it means

week(date) returns Calendar.WEEK_OF_YEAR as a Double. It requires exactly one argument; with any other count it throws this RuntimeException, and other internal failures surface via the catch as e.toString().

Solutions

  1. Call week() with exactly one Date argument.
  2. Convert string inputs with str2date() first.
  3. Null-check the date before calling week().
  4. If week numbering looks wrong, verify the JVM locale/first-day-of-week settings rather than the call arity.

Example fix

// before
var w = week(dateString);
// after
var w = week(str2date(dateString, "yyyy-MM-dd"));
Defensive patterns

Strategy: validation

Validate before calling

var w = (d != null) ? week(d) : null;

Type guard

function isKettleDate(v) { return v != null && v instanceof java.util.Date; }

Try / catch

try {
  var w = week(d);
} catch (e) {
  Logger.LogBasic("week failed: " + e.message);
  w = null;
}

Prevention

When it happens

Trigger: Calling week() with zero or multiple arguments in a Script step; passing a non-Date argument that fails the cast.

Common situations: Passing string dates; locale-dependent week numbering surprises (WEEK_OF_YEAR depends on the JVM's default Calendar locale); missing argument after refactoring.

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


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:916

      throw new RuntimeException( e.toString() );
    }
  }

  public static Object week( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    try {
      if ( ArgList.length == 1 ) {
        if ( isNull( ArgList[0] ) ) {
          return new Double( Double.NaN );
        } else if ( isUndefined( ArgList[0] ) ) {
          return undefinedValue;
        }
        java.util.Date dArg1 = (java.util.Date) ArgList[0];
        Calendar cal = Calendar.getInstance();
        cal.setTime( dArg1 );
        return new Double( cal.get( Calendar.WEEK_OF_YEAR ) );
      } else {
        throw new RuntimeException( "The function call week requires 1 argument." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( e.toString() );
    }
  }

  public static Object str2RegExp( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String[] strArr = null;
    if ( ArgList.length == 2 ) {
      try {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return undefinedValue;
        }
        String strToMatch = (String) ArgList[0];
        Pattern p = Pattern.compile( (String) ArgList[1] );

View on GitHub (pinned to f3058517a1)