{"record":{"id":"6a570bbe1a17346e","repo":"pentaho/pentaho-kettle","slug":"the-function-call-trim-requires-1-argument","errorCode":null,"errorMessage":"The function call trim requires 1 argument.","messagePattern":"The function call trim 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":1592,"sourceCode":"  }\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        }\n        sRC = (String) ArgList[0];\n        int from = (int) Math.round( (Double) ArgList[1] );\n        sRC = sRC.substring( from );","sourceCodeStart":1574,"sourceCodeEnd":1610,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1574-L1610","documentation":"Arity guard for the trim script function: it was called with more (or fewer) than one argument. trim strips whitespace from a single string via Const.trim, so exactly one argument is required; the else-branch rejects all other counts.","triggerScenarios":"Calling trim() with zero arguments or trim(a, b) with extra arguments in JavaScript step code.","commonSituations":"Mistakenly calling trim on multiple fields at once (expecting variadic behavior); copy-paste errors leaving an extra comma.","solutions":["Call trim with exactly one argument per field: trim(field1); trim(field2).","Remove extra arguments; trim does not accept a character-set argument like some other languages' APIs.","If you need multi-field trimming, write a small wrapper loop in the script."],"exampleFix":"// before\nvar t = trim(a, b);\n// after\nvar t = trim(a); var t2 = trim(b);","handlingStrategy":"validation","validationCode":"if (arguments.length === 1) { t = trim(arguments[0]); } else { t = ''; }","typeGuard":"function hasOneArg(args){ return args.length === 1; }","tryCatchPattern":"try { t = trim(value); } catch (e) { if (/requires 1 argument/.test(e.message)) t = ''; else throw e; }","preventionTips":["One call per field; trim is not variadic.","No character-set second argument — unlike Java's String.trim alternatives.","Lint scripts for stray commas."],"tags":["javascript","argument-count","trim","script-step"],"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"}