{"record":{"id":"2ea52df1f4033fc8","repo":"pentaho/pentaho-kettle","slug":"the-function-call-decode-is-not-valid","errorCode":null,"errorMessage":"The function call decode is not valid : ","messagePattern":"The function call decode is not valid : ","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1537,"sourceCode":"        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return Context.getUndefinedValue();\n        }\n        Object objToCompare = ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          if ( ArgList[i].equals( objToCompare ) ) {\n            return ArgList[i + 1];\n          }\n        }\n        if ( ArgList.length % 2 == 0 ) {\n          return ArgList[ArgList.length - 1];\n        } else {\n          return objToCompare;\n        }\n      } else {\n        throw Context.reportRuntimeError( \"The function call decode requires more than 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call decode is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String replace( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        String objForReplace = Context.toString( ArgList[0] );\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          objForReplace =\n            objForReplace.replaceAll( Context.toString( ArgList[i] ), Context.toString( ArgList[i + 1] ) );\n        }\n        return objForReplace;","sourceCodeStart":1519,"sourceCodeEnd":1555,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1519-L1555","documentation":"The `decode()` ScriptValuesMod function wraps its whole comparison logic in a try/catch and re-throws any exception (regex-free string comparison failures, invalid types, Context conversion errors) as this runtime error with the original message appended. The message shown was empty, meaning the underlying exception had a null/blank getMessage().","triggerScenarios":"Any runtime exception inside decode's comparison loop: null values being compared via equals without guarding, incompatible object types passed as ArgList, or Context.toString conversion failures where e.getMessage() returns null.","commonSituations":"Passing null fields from a previous step into decode(); passing non-string/non-comparable objects (e.g. binary, Number vs String) as search values; Kettle field values that are null on the first row.","solutions":["Guard input values with a null check before calling decode (e.g. `value == null ? def : decode(value, ...)`)","Convert fields to strings explicitly before passing them: decode(str(value), ...)","Rebuild the message by enabling the underlying exception: log ArgList types before calling decode to find the offending value"],"exampleFix":"// before\nvar out = decode(fieldA, 'x', 1, 0);\n// after\nvar out = (fieldA == null) ? 0 : decode(Context.toString(fieldA), 'x', 1, 0);","handlingStrategy":"type-guard","validationCode":"if (value == null) { logError('decode input is null'); } else { var out = decode(String(value), 'x', 1, 0); }","typeGuard":"function isSafeForDecode(v) { return v !== null && v !== undefined; }","tryCatchPattern":"try {\n  var out = decode(v, 'x', 1, 0);\n} catch (e) {\n  if (String(e).indexOf('decode is not valid') !== -1) { out = 0; } else { throw e; }\n}","preventionTips":["Null-guard every field read from the row before decode","Coerce numeric fields to strings before comparison","Test the JavaScript step with sample rows including nulls"],"tags":["javascript","pentaho","scripting","wrapped-exception"],"backgroundTag":"invalid-argument-value","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"}