{"record":{"id":"beeab079314928bb","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rtrim-requires-1-argument","errorCode":null,"errorMessage":"The function call rtrim requires 1 argument.","messagePattern":"The function call rtrim 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":770,"sourceCode":"      }\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 {\n        throw new RuntimeException( \"The function call rtrim requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call rtrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String lpad( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    // (String valueToPad, String filler, int size) {\n    try {\n      if ( ArgList.length == 3 ) {\n        if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return (String) undefinedValue;\n        }\n        String valueToPad = (String) ArgList[0];","sourceCodeStart":752,"sourceCodeEnd":788,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L752-L788","documentation":"rtrim strips trailing whitespace from a string and requires exactly one argument. When ArgList.length != 1 it throws this RuntimeException. Symmetric to ltrim's guard, this check runs before any trimming work.","triggerScenarios":"Calling rtrim() with no arguments, or rtrim(str, chars) passing a character-set second argument that this API does not accept.","commonSituations":"Porting code from rtrim variants that take a character list; forgetting to pass the field because another function bound it implicitly.","solutions":["Call with exactly one argument: rtrim(str).","Remove extra arguments; for custom trailing characters use str.replace(/\\s+$/, '') or a targeted regex in JavaScript.","Convert non-string values with String(value) before calling to also avoid the related 'not valid' wrapper error."],"exampleFix":"// before\nvar trimmed = rtrim(name, '\\t');\n// after\nvar trimmed = rtrim(name);","handlingStrategy":"validation","validationCode":"if (arguments.length !== 1 || typeof str !== 'string') {\n  throw new Error('rtrim requires exactly one string argument');\n}\nvar trimmed = rtrim(str);","typeGuard":"function isStringArg(v) { return typeof v === 'string' || v instanceof String; }","tryCatchPattern":"try {\n  var trimmed = rtrim(str);\n} catch (e) {\n  if (String(e.message).indexOf('requires 1 argument') !== -1) {\n    throw new Error('Call rtrim with exactly one argument');\n  } else { throw e; }\n}","preventionTips":["Call rtrim with exactly one argument; no character-set parameter is supported.","Use str.replace(/\\s+$/, '') for trimming custom trailing characters.","Coerce non-string values with String(value) before calling."],"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"}