pentaho/pentaho-kettle · error · RuntimeException

The function call getEnvironmentVar requires 1 argument.

Error message

The function call getEnvironmentVar requires 1 argument.

What it means

Thrown by the JavaScript step's getEnvironmentVar helper when it is called with an argument count other than 1. The helper wraps System.getProperty and requires exactly one string argument naming the environment/system property to read. It is a fail-fast arity check, not a lookup failure.

Solutions

  1. Pass exactly one string argument: getEnvironmentVar('MY_VAR').
  2. If you need a default value, supply it in script: var v = getEnvironmentVar('MY_VAR') || 'default';
  3. Check the script for stray commas or leftover arguments from a refactor.

Example fix

// before
var env = getEnvironmentVar();
// after
var env = getEnvironmentVar('MY_ENV_VAR');
Defensive patterns

Strategy: validation

Validate before calling

// before calling in JS
var v;
if (arguments.length === 1 && typeof arguments[0] === 'string') v = getEnvironmentVar(arguments[0]);
else throw new Error('getEnvironmentVar needs exactly 1 string argument');

Type guard

function isSingleStringArg(args){ return Array.isArray(args) && args.length === 1 && typeof args[0] === 'string'; }

Try / catch

try { var v = getEnvironmentVar('MY_VAR'); } catch (e) { var v = ''; /* arity or missing var */ }

Prevention

When it happens

Trigger: Calling getEnvironmentVar() with no arguments or with 2+ arguments inside JavaScript code of the 'JavaScript' (script) transformation step.

Common situations: Copy-pasted script snippets where the argument was accidentally deleted; refactoring a script from getenv-style APIs that take zero arguments; passing a second default-value argument out of habit from other env-var APIs.

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

Appendix: source

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

      }
    } else {
      throw new RuntimeException( "The function call setEnvironmentVar requires 2 arguments." );
    }
  }

  // Returning EnvironmentVar
  public static String getEnvironmentVar( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String sRC = "";
    if ( ArgList.length == 1 ) {
      try {
        String sArg1 = (String) ArgList[0];
        sRC = System.getProperty( sArg1, "" );
      } catch ( Exception e ) {
        sRC = "";
      }
    } else {
      throw new RuntimeException( "The function call getEnvironmentVar requires 1 argument." );
    }
    return sRC;
  }

  public static String trim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String sRC = "";
    if ( ArgList.length == 1 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) undefinedValue;
        }
        sRC = (String) ArgList[0];
        sRC = Const.trim( sRC );
      } catch ( Exception e ) {
        throw new RuntimeException( "The function call trim is not valid : " + e.getMessage() );

View on GitHub (pinned to f3058517a1)