{"record":{"id":"4ae15a4027977c90","repo":"pentaho/pentaho-kettle","slug":"the-function-call-ltrim-is-not-valid-4ae15a","errorCode":null,"errorMessage":"The function call ltrim is not valid : ","messagePattern":"The function call ltrim is not valid : ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":784,"sourceCode":"    return Boolean.valueOf( bRC );\n  }\n\n  public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        String strValueToTrim = Context.toString( ArgList[0] );\n        return strValueToTrim.replaceAll( \"^\\\\s+\", \"\" );\n      } else {\n        throw Context.reportRuntimeError( \"The function call ltrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call ltrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        String strValueToTrim = Context.toString( ArgList[0] );\n        return strValueToTrim.replaceAll( \"\\\\s+$\", \"\" );\n      } else {\n        throw Context.reportRuntimeError( \"The function call rtrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {","sourceCodeStart":766,"sourceCodeEnd":802,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L766-L802","documentation":"This is ltrim's generic wrapper exception: any Exception thrown while processing a valid single-argument call (e.g. a Rhino conversion failure or regex error) is re-thrown as 'The function call ltrim is not valid : ' + e.getMessage(). The empty message here means the underlying exception's getMessage() returned null.","triggerScenarios":"Passing a non-string object whose Context.toString conversion throws, or an underlying exception with a null message (common with NullPointerExceptions) inside the try block of ltrim.","commonSituations":"Passing null/undefined-adjacent values from upstream fields into ltrim; passing Rhino Java objects that fail conversion; debugging confusion because the real cause is hidden by the null message.","solutions":["Log/inspect the actual field value fed to ltrim; convert it explicitly with value + '' or Context-safe toString before the call","Guard against null: use (value == null ? '' : value) before ltrim","Check the step log for the preceding stack trace to identify the wrapped exception"],"exampleFix":"// before\nvar s = ltrim(row.rawField);\n// after\nvar s = ltrim(row.rawField == null ? '' : String(row.rawField));","handlingStrategy":"try-catch","validationCode":"var safe = (v == null) ? '' : String(v);\nvar t = ltrim(safe);","typeGuard":"function isNonNullString(v) { return typeof v === 'string' && v !== null; }","tryCatchPattern":"try { var t = ltrim(s); } catch (e) { // generic wrapper: message may be empty\n  throw new Error('ltrim failed on value: ' + JSON.stringify(s) + ' cause: ' + e.message); }","preventionTips":["Null-check and stringify inputs before ltrim to avoid the opaque wrapper error","Replace direct calls with a safe wrapper that logs the input value on failure","Investigate null-message exceptions via the step's full log stack trace"],"tags":["javascript","kettle","string","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"}