{"record":{"id":"8229098f59881071","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getenvironmentvar-requires-1-argument","errorCode":null,"errorMessage":"The function call getEnvironmentVar requires 1 argument.","messagePattern":"The function call getEnvironmentVar requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1571,"sourceCode":"      }\n    } else {\n      throw new RuntimeException( \"The function call setEnvironmentVar requires 2 arguments.\" );\n    }\n  }\n\n  // Returning EnvironmentVar\n  public static String getEnvironmentVar( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        String sArg1 = (String) ArgList[0];\n        sRC = System.getProperty( sArg1, \"\" );\n      } catch ( Exception e ) {\n        sRC = \"\";\n      }\n    } else {\n      throw new RuntimeException( \"The function call getEnvironmentVar requires 1 argument.\" );\n    }\n    return sRC;\n  }\n\n  public static String trim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) undefinedValue;\n        }\n        sRC = (String) ArgList[0];\n        sRC = Const.trim( sRC );\n      } catch ( Exception e ) {\n        throw new RuntimeException( \"The function call trim is not valid : \" + e.getMessage() );","sourceCodeStart":1553,"sourceCodeEnd":1589,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1553-L1589","documentation":"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.","triggerScenarios":"Calling getEnvironmentVar() with no arguments or with 2+ arguments inside JavaScript code of the 'JavaScript' (script) transformation step.","commonSituations":"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.","solutions":["Pass exactly one string argument: getEnvironmentVar('MY_VAR').","If you need a default value, supply it in script: var v = getEnvironmentVar('MY_VAR') || 'default';","Check the script for stray commas or leftover arguments from a refactor."],"exampleFix":"// before\nvar env = getEnvironmentVar();\n// after\nvar env = getEnvironmentVar('MY_ENV_VAR');","handlingStrategy":"validation","validationCode":"// before calling in JS\nvar v;\nif (arguments.length === 1 && typeof arguments[0] === 'string') v = getEnvironmentVar(arguments[0]);\nelse throw new Error('getEnvironmentVar needs exactly 1 string argument');","typeGuard":"function isSingleStringArg(args){ return Array.isArray(args) && args.length === 1 && typeof args[0] === 'string'; }","tryCatchPattern":"try { var v = getEnvironmentVar('MY_VAR'); } catch (e) { var v = ''; /* arity or missing var */ }","preventionTips":["Always pass exactly one string argument.","Provide defaults in script with || instead of extra arguments.","Review step functions via the JavaScript step's function list before use."],"tags":["javascript","argument-count","script-step"],"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"}