pentaho/pentaho-kettle · error

The function call trunc requires 1 argument, a number.

Error message

The function call trunc requires 1 argument, a number.

What it means

trunc() truncates a number to its integer part via Math.floor. This error is thrown when the JS call does not supply exactly 1 argument (the else branch), meaning the function's signature contract was violated. Note it truncates toward negative infinity, which surprises some users, but this specific message is purely an argument-count failure.

Solutions

  1. Call trunc with exactly one numeric argument: trunc(value).
  2. Use truncDate(date, level) instead when the argument is a Date.
  3. Convert strings to numbers first: trunc(parseFloat(str)) or trunc(new Number(str).doubleValue()).
  4. Check upstream field types; a field typed as String may still pass but a wrong arg count will not.

Example fix

// before
var t = trunc(amount, 2); // wrong: extra precision arg
// after
var t = trunc(amount); // floors to integer; use your own scaling for 2 decimals
Defensive patterns

Strategy: validation

Validate before calling

function safeTrunc(v) { if (v == null || isNaN(parseFloat(v))) return null; return trunc(parseFloat(v)); }

Type guard

function isNumber(v) { return typeof v === 'number' && !isNaN(v); }

Try / catch

try { t = trunc(x); } catch (e) { Logger.LogError('trunc failed: ' + e.message); t = null; }

Prevention

When it happens

Trigger: trunc() with no arguments, trunc(x, y) with extra arguments, or any call where ArgList length differs from 1 in a Modified Java Script Value step.

Common situations: Porting Oracle/Excel TRUNC(date|number, fmt) habits into Kettle JS and passing a second precision argument; calling trunc on a date intending truncDate instead.

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/b3d25f9dab5920a9. Report an issue: GitHub.

Appendix: source

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

  public static Object trunc( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      // 1 argument: normal truncation of numbers
      //
      if ( ArgList.length == 1 ) {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return Context.getUndefinedValue();
        }

        // This is the truncation of a number...
        //
        Double dArg1 = (Double) Context.jsToJava( ArgList[0], Double.class );
        return Double.valueOf( Math.floor( dArg1 ) );

      } else {
        throw Context.reportRuntimeError( "The function call trunc requires 1 argument, a number." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( e.toString() );
    }
  }

  @SuppressWarnings( "fallthrough" )
  public static Object truncDate( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) {
      // 2 arguments: truncation of dates to a certain precision
      //
    if ( ArgList.length == 2 ) {
      if ( isNull( ArgList[0] ) ) {
        return null;
      } else if ( isUndefined( ArgList[0] ) ) {
        return Context.getUndefinedValue();
      }

      // This is the truncation of a date...

View on GitHub (pinned to f3058517a1)