{"record":{"id":"8ecc4abcd3c7821c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-ltrim-requires-1-argument","errorCode":null,"errorMessage":"The function call ltrim requires 1 argument.","messagePattern":"The function call ltrim requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":751,"sourceCode":"    } else {\n      throw new RuntimeException( \"The function call isCodepage requires 2 arguments.\" );\n    }\n    return Boolean.valueOf( bRC );\n  }\n\n  public static String ltrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String strValueToTrim = (String) ArgList[0];\n        return strValueToTrim.replaceAll( \"^\\\\s+\", \"\" );\n      } else {\n        throw new RuntimeException( \"The function call ltrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call ltrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String rtrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String strValueToTrim = (String) ArgList[0];\n        return strValueToTrim.replaceAll( \"\\\\s+$\", \"\" );\n      } else {","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L733-L769","documentation":"ltrim strips leading whitespace from a string and requires exactly one argument. When ArgList.length != 1 it throws this RuntimeException. The check sits inside an outer try, but this specific throw happens before the per-argument processing.","triggerScenarios":"Calling ltrim() with no arguments, or ltrim(str, chars) with a second character-set argument (not supported by this API).","commonSituations":"Porting from ltrim implementations (e.g. Oracle/PHP) that accept a character list as the second argument; calling without arguments expecting it to operate on a bound field.","solutions":["Call with exactly one argument: ltrim(str).","Remove any second character-set argument; if you need custom trimming, use str.replace(/^\\s+/, '') or a char-class regex in JavaScript.","Ensure the field value is passed explicitly, not assumed from context."],"exampleFix":"// before\nvar trimmed = ltrim(name, ' ');\n// after\nvar trimmed = ltrim(name);","handlingStrategy":"validation","validationCode":"if (arguments.length !== 1 || typeof str !== 'string') {\n  throw new Error('ltrim requires exactly one string argument');\n}\nvar trimmed = ltrim(str);","typeGuard":"function isStringArg(v) { return typeof v === 'string' || v instanceof String; }","tryCatchPattern":"try {\n  var trimmed = ltrim(str);\n} catch (e) {\n  if (String(e.message).indexOf('requires 1 argument') !== -1) {\n    throw new Error('Call ltrim with exactly one argument');\n  } else { throw e; }\n}","preventionTips":["Call ltrim with exactly one argument; it has no character-set parameter.","Use str.replace(/^\\s+/, '') directly for custom trimming needs.","Pass the field value explicitly rather than relying on implicit bindings."],"tags":["javascript","argument-count","string","pentaho-kettle"],"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"}