{"record":{"id":"698485de4261ac56","repo":"pentaho/pentaho-kettle","slug":"the-function-call-ltrim-requires-1-argument-698485","errorCode":null,"errorMessage":"The function call ltrim requires 1 argument.","messagePattern":"The function call ltrim requires 1 argument\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":781,"sourceCode":"    } else {\n      throw Context.reportRuntimeError( \"The function call isCodepage requires 2 arguments.\" );\n    }\n    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 {","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L763-L799","documentation":"Argument-count guard in ScriptValuesAddedFunctions.ltrim, which strips leading whitespace from a string. It fires when a JavaScript script calls ltrim with an argument count other than exactly 1; the guard raises a Rhino runtime error instead of proceeding. Fix by passing exactly one string argument, e.g. ltrim(myField).","triggerScenarios":"Calling ltrim() with no arguments, or ltrim(str, chars) with a second 'characters to trim' argument that this implementation does not accept.","commonSituations":"Users coming from SQL LTRIM(expr, set) or Oracle syntax expecting a character-set parameter; calling with a comma-separated list intended as one argument.","solutions":["Call with a single string argument: ltrim(myString)","For custom character trimming, use myString.replace(/^[chars]+/, '') directly","Ensure the argument is a string (or undefined-aware) before calling"],"exampleFix":"// before\nvar s = ltrim(value, ' ');\n// after\nvar s = ltrim(value);","handlingStrategy":"type-guard","validationCode":"if (typeof s !== 'string') s = String(s == null ? '' : s);\nvar t = ltrim(s);","typeGuard":"function isStr(v) { return typeof v === 'string'; }","tryCatchPattern":"try { var t = ltrim(s); } catch (e) { if (String(e).indexOf('requires 1 argument') >= 0) { /* fix arity */ } else { throw e; } }","preventionTips":["Call ltrim with exactly one argument; use regex replace for custom character sets","Coerce non-string fields to strings first","Never mimic SQL LTRIM(expr, set) syntax here"],"tags":["javascript","kettle","string","argument-count"],"backgroundTag":"missing-required-argument","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"}