{"record":{"id":"6868bf36cc9fafd1","repo":"pentaho/pentaho-kettle","slug":"the-function-call-rtrim-is-not-valid-6868bf","errorCode":null,"errorMessage":"The function call rtrim is not valid : ","messagePattern":"The function call rtrim 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":803,"sourceCode":"    }\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 ) {\n      throw Context.reportRuntimeError( \"The function call rtrim is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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) Context.getUndefinedValue();\n        }\n        String valueToPad = Context.toString( ArgList[0] );\n        String filler = Context.toString( ArgList[1] );\n        int size = (int) Context.toNumber( ArgList[2] );\n","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L785-L821","documentation":"In Kettle/Pentaho's JavaScript scripting step (ScriptValuesAddedFunctions), the rtrim() JS function trims trailing whitespace via a regex replaceAll. Any exception thrown inside rtrim() — including wrong argument counts or non-string arguments — is caught and re-thrown as this generic 'The function call rtrim is not valid' runtime error, with the underlying message appended.","triggerScenarios":"Calling rtrim() in a modified JavaScript step with zero arguments (hits the requires-1-argument branch first), or with an argument that cannot be converted or causes an exception inside the regex replace (e.g. null/undefined value passed from a field).","commonSituations":"Script authors pass a null field value to rtrim(), forget the argument entirely, or pass a non-string object; the wrapper catches the resulting exception and surfaces it with this message.","solutions":["Ensure rtrim() is called with exactly one argument that is a defined value.","Null-check the field value in the script before calling rtrim().","Inspect the appended e.getMessage() in the error to find the real underlying cause.","Log the argument value before the call to confirm its type/content."],"exampleFix":"// before\nvar trimmed = rtrim(myField); // myField may be null\n// after\nvar trimmed = (myField != null) ? rtrim(myField.toString()) : null;","handlingStrategy":"validation","validationCode":"if (typeof myField === 'undefined' || myField === null) { throw 'rtrim: input field is null'; }\nvar trimmed = rtrim(String(myField));","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { var trimmed = rtrim(String(myField)); } catch (e) { // fall back to untrimmed value\n  var trimmed = String(myField); }","preventionTips":["Always pass exactly one string argument to rtrim()","Null-check Kettle field values before string functions","Use String(...) to coerce fields before calling","Read the full error message: the cause is appended after the colon"],"tags":["javascript","rhino","string-functions"],"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"}