{"record":{"id":"ca4e6dbe3df7c46e","repo":"pentaho/pentaho-kettle","slug":"the-function-call-decode-is-not-valid-e-getmessage","errorCode":null,"errorMessage":"The function call decode is not valid : \" + e.getMessage()","messagePattern":"The function call decode is not valid : \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1502,"sourceCode":"        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return undefinedValue;\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 new RuntimeException( \"The function call decode requires more than 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call decode is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String replace( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String objForReplace = (String) ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          objForReplace = objForReplace.replaceAll( (String) ArgList[i], (String) ArgList[i + 1] );\n        }\n        return objForReplace;\n      } else {","sourceCodeStart":1484,"sourceCodeEnd":1520,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1484-L1520","documentation":"decode wraps any exception thrown inside its comparison logic in a new RuntimeException prefixed with 'The function call decode is not valid : '. This can be triggered by argument-count problems caught inside the try block or errors while evaluating the comparison values, and it flattens the original exception to just its message.","triggerScenarios":"Any Exception during decode execution - including inner arithmetic/cast errors or a caught arity error - surfaces with this message in a JavaScript step.","commonSituations":"Passing non-comparable object types to decode, null values failing casts, nested decode errors whose messages get concatenated.","solutions":["Check the trailing message after the colon to identify the root cause.","Validate argument types and count before calling decode (more than 1 argument).","Replace complex decode calls with explicit if/else in the script for easier debugging."],"exampleFix":"// before\nvar r = decode(null, x, 1, 0); // may throw with cast/NPE message\n// after\nvar r = (status == null) ? 0 : decode(status, x, 1, 0);","handlingStrategy":"try-catch","validationCode":"function safeDecode() {\n  if (arguments.length < 2) return arguments.length ? arguments[0] : null;\n  try { return decode.apply(null, arguments); }\n  catch (e) { return null; }\n}","typeGuard":"function allStrings(arr) {\n  return arr.every(function(a) { return typeof a === 'string' || a === null; });\n}","tryCatchPattern":"try {\n  var r = decode(status, 'A', 1, 0);\n} catch (e) {\n  // message after 'not valid : ' names the root cause - log it fully\n  Logger.log(e.message);\n  var r = 0;\n}","preventionTips":["Null-check values before decode.","Keep decode arguments simple/comparable; use if/else for complex logic.","Read the appended root-cause message for diagnosis."],"tags":["java","pdi","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"}