pentaho/pentaho-kettle · error
The function call ltrim is not valid :
Error message
The function call ltrim is not valid :
What it means
This is ltrim's generic wrapper exception: any Exception thrown while processing a valid single-argument call (e.g. a Rhino conversion failure or regex error) is re-thrown as 'The function call ltrim is not valid : ' + e.getMessage(). The empty message here means the underlying exception's getMessage() returned null.
Solutions
- Log/inspect the actual field value fed to ltrim; convert it explicitly with value + '' or Context-safe toString before the call
- Guard against null: use (value == null ? '' : value) before ltrim
- Check the step log for the preceding stack trace to identify the wrapped exception
Example fix
// before var s = ltrim(row.rawField); // after var s = ltrim(row.rawField == null ? '' : String(row.rawField));
Defensive patterns
Strategy: try-catch
Validate before calling
var safe = (v == null) ? '' : String(v); var t = ltrim(safe);
Type guard
function isNonNullString(v) { return typeof v === 'string' && v !== null; } Try / catch
try { var t = ltrim(s); } catch (e) { // generic wrapper: message may be empty
throw new Error('ltrim failed on value: ' + JSON.stringify(s) + ' cause: ' + e.message); } Prevention
- Null-check and stringify inputs before ltrim to avoid the opaque wrapper error
- Replace direct calls with a safe wrapper that logs the input value on failure
- Investigate null-message exceptions via the step's full log stack trace
When it happens
Trigger: Passing a non-string object whose Context.toString conversion throws, or an underlying exception with a null message (common with NullPointerExceptions) inside the try block of ltrim.
Common situations: Passing null/undefined-adjacent values from upstream fields into ltrim; passing Rhino Java objects that fail conversion; debugging confusion because the real cause is hidden by the null message.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Please provide a valid Char to the fillString
- The function call fillString requires 2 arguments.
- The function call ltrim requires 1 argument.
- The function call rtrim requires 1 argument.
- AbsSecurityManager.ERROR_0004_UNABLE_TO_APPLY_LOGICAL_ROLES_TO_RUNTIME_ROLE
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/4ae15a4027977c90.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:784
return Boolean.valueOf( bRC );
}
public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return (String) Context.getUndefinedValue();
}
String strValueToTrim = Context.toString( ArgList[0] );
return strValueToTrim.replaceAll( "^\\s+", "" );
} else {
throw Context.reportRuntimeError( "The function call ltrim requires 1 argument." );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( "The function call ltrim is not valid : " + e.getMessage() );
}
}
public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return (String) Context.getUndefinedValue();
}
String strValueToTrim = Context.toString( ArgList[0] );
return strValueToTrim.replaceAll( "\\s+$", "" );
} else {
throw Context.reportRuntimeError( "The function call rtrim requires 1 argument." );
}
} catch ( Exception e ) {View on GitHub (pinned to f3058517a1)