pentaho/pentaho-kettle · error · RuntimeException
The function call ltrim is not valid :
Error message
The function call ltrim is not valid :
What it means
ltrim wraps all processing in a try/catch; any exception (most commonly a ClassCastException when ArgList[0] is not a String) is rethrown as RuntimeException('The function call ltrim is not valid : ' + e.getMessage()). Unlike the other wrappers it uses getMessage(), which is often null, yielding a message that ends with a dangling colon and no cause.
Solutions
- Convert the argument to a string first: ltrim(String(value)).
- Because getMessage() may be null, log e in the script or test the argument type before calling to get a clearer failure.
- Guard null/undefined with isUndefined(ArgList[0]) before calling ltrim.
- Coerce numeric fields with str2num/str functions or JavaScript String() before trimming.
Example fix
// before var trimmed = ltrim(idField); // idField is a number // after var trimmed = ltrim(String(idField));
Defensive patterns
Strategy: type-guard
Validate before calling
if (str === null || str === undefined) return str; if (typeof str !== 'string') str = String(str); var trimmed = ltrim(str);
Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; } Try / catch
try {
var trimmed = ltrim(str);
} catch (e) {
// getMessage() may be null; wrap with argument info
throw new Error('ltrim failed on value: ' + str + ' (' + e + ')');
} Prevention
- Convert non-string fields with String(value) before trimming.
- Check isUndefined(ArgList[0]) for potentially missing stream fields.
- Watch for the dangling-colon message: it means a non-string argument reached the cast.
- Normalize numeric and date fields to strings early in the script.
When it happens
Trigger: Calling ltrim with a non-string first argument (number, date, null) so the (String) cast or replaceAll call throws inside the try block.
Common situations: Passing numeric stream fields directly without String() conversion; passing null dates; empty bindings where the variable is undefined (use isUndefined first).
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Could not convert to the given local format.
- Please provide a filename to the function call…
- Please provide a valid Char to the fillString
- The function call date2str requires 1, 2, 3, or 4 arguments.
- The function call dateAdd requires 3 arguments.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/2a39101cf31365c2.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:754
return Boolean.valueOf( bRC );
}
public static String ltrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return (String) undefinedValue;
}
String strValueToTrim = (String) ArgList[0];
return strValueToTrim.replaceAll( "^\\s+", "" );
} else {
throw new RuntimeException( "The function call ltrim requires 1 argument." );
}
} catch ( Exception e ) {
throw new RuntimeException( "The function call ltrim is not valid : " + e.getMessage() );
}
}
public static String rtrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return (String) undefinedValue;
}
String strValueToTrim = (String) ArgList[0];
return strValueToTrim.replaceAll( "\\s+$", "" );
} else {
throw new RuntimeException( "The function call rtrim requires 1 argument." );
}
} catch ( Exception e ) {View on GitHub (pinned to f3058517a1)