{"record":{"id":"aa038c38af6bcf6f","repo":"pentaho/pentaho-kettle","slug":"the-function-call-trim-is-not-valid","errorCode":null,"errorMessage":"The function call trim is not valid : ","messagePattern":"The function call trim is not valid : ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1589,"sourceCode":"      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() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call trim requires 1 argument.\" );\n    }\n    return sRC;\n  }\n\n  public static String substr( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) undefinedValue;\n        }","sourceCodeStart":1571,"sourceCodeEnd":1607,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1571-L1607","documentation":"Thrown when the trim() helper in the JavaScript step throws any exception while processing its single argument (the arity error at the same call site is separate). The message appends the underlying exception text after the colon. It typically means the argument could not be cast/handled as a string.","triggerScenarios":"Calling trim(x) where x is not a string (e.g. a number, null at runtime, or an object) so (String) ArgList[0] or Const.trim throws; also when ArgList[0] is a value that fails conversion in the try block.","commonSituations":"Trimming a numeric field read from a row without converting it; trimming a field that is null; feeding the output of another function that returned a non-string.","solutions":["Convert the value explicitly before trimming: trim('' + value) or trim(value.toString()).","Guard against null: trim(value == null ? '' : value + '').","Read the appended e.getMessage() in the message to identify the actual failure."],"exampleFix":"// before\nvar t = trim(123);\n// after\nvar t = trim('' + 123);","handlingStrategy":"type-guard","validationCode":"function safeTrim(v){ return (v === null || v === undefined) ? '' : Const.trim('' + v); }","typeGuard":"function isTrimable(v){ return v !== null && v !== undefined; }","tryCatchPattern":"try { t = trim(value); } catch (e) { t = ''; logError('trim failed: ' + e.message); }","preventionTips":["Coerce fields to strings before trimming ('' + value).","Null-check row fields before use.","Trim only fields verified as String type in the row layout."],"tags":["javascript","trim","type-error","script-step"],"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"}