pentaho/pentaho-kettle · error · RhinoRuntimeError
The argument type of function call setVariable should…
Error message
The argument type of function call setVariable should either be "s", "r", "p", or "g".
What it means
setVariable()'s third argument selects the variable scope and must be one of 's' (system), 'r' (root), 'p' (parent), or 'g' (grand-parent). The implementation maps the string via a switch whose default branch throws this Rhino runtime error for any unrecognized scope. It prevents silently writing variables into an unintended scope.
Solutions
- Use one of the four accepted scope strings: 's', 'r', 'p', or 'g' (lowercase).
- Pass VariableScope-appropriate scope: 's' system, 'r' root, 'p' parent transformation, 'g' grand-parent.
- Guard the scope in script before calling setVariable.
Example fix
// before setVariable(val, 'MY_VAR', 'system'); // after setVariable(val, 'MY_VAR', 's');
Defensive patterns
Strategy: validation
Validate before calling
var scope = 'r';
if (['s','r','p','g'].indexOf(scope) === -1) throw new Error('invalid scope ' + scope); Try / catch
try { setVariable(val, name, scope); } catch (e) { if (String(e).indexOf('argument type') >= 0) setVariable(val, name, 'r'); else throw e; } Prevention
- Memorize the four scope letters: s, r, p, g — always lowercase.
- Centralize scope strings as constants in shared script snippets.
- Never pass scope constants from other frameworks.
When it happens
Trigger: setVariable(value, 'MY_VAR', 'X') or setVariable(value, name, null) or an empty-string scope — any third argument other than 's','r','p','g'.
Common situations: Typos like 'S' or 'root'; passing a numeric scope constant from another framework; localization mistakes; forgetting the scope is a single lowercase letter.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Alert dialog cancelled by user.
- Could not convert the String with the given format :
- e.getMessage()
- Function call replace is not valid :
- rule.select.module
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/48b34243b0049ac5.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1908
if ( grandParentSpace != null ) {
grandParentSpace.setVariable( variableName, variableValue );
}
}
}
static VariableScope getVariableScope( String codeOfScope ) {
switch ( codeOfScope ) {
case "s":
return VariableScope.SYSTEM;
case "r":
return VariableScope.ROOT;
case "p":
return VariableScope.PARENT;
case "g":
return VariableScope.GRAND_PARENT;
default:
throw Context.reportRuntimeError( "The argument type of function call "
+ "setVariable should either be \"s\", \"r\", \"p\", or \"g\"." );
}
}
// Returning EnvironmentVar
public static String getVariable( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
String sRC = "";
String sArg1 = "";
String sArg2 = "";
if ( ArgList.length == 2 ) {
try {
Object scmo = actualObject.get( "_step_", actualObject );
Object scmO = Context.jsToJava( scmo, StepInterface.class );
if ( scmO instanceof StepInterface ) {
StepInterface scm = (StepInterface) Context.jsToJava( scmO, StepInterface.class );
View on GitHub (pinned to f3058517a1)