pentaho/pentaho-kettle · error · RuntimeException
The function call isCodepage requires 2 arguments.
Error message
The function call isCodepage requires 2 arguments.
What it means
isCodepage tests whether a byte array/string can be decoded with a given codepage. It requires exactly two arguments (the data and the codepage name); with any other count it throws this RuntimeException rather than returning a result. Note that decode failures inside the try block merely set bRC=false; only the wrong argument count throws.
Solutions
- Call with exactly two arguments: isCodepage(data, 'UTF-8').
- Supply the codepage name as a string, e.g. 'UTF-8', 'ISO-8859-1'.
- If unsure of the encoding, test candidate codepages with separate two-argument calls.
Example fix
// before var ok = isCodepage(rawBytes); // after var ok = isCodepage(rawBytes, 'ISO-8859-1');
Defensive patterns
Strategy: validation
Validate before calling
if (arguments.length !== 2 || typeof codepage !== 'string') {
throw new Error('isCodepage requires exactly 2 arguments: (data, codepage)');
}
var ok = isCodepage(data, codepage); Type guard
function isCodepageCall(d, c) { return d != null && typeof c === 'string' && c.length > 0; } Try / catch
try {
var ok = isCodepage(data, codepage);
} catch (e) {
if (String(e.message).indexOf('requires 2 arguments') !== -1) {
throw new Error('Call isCodepage as isCodepage(data, codepageName)');
} else { throw e; }
} Prevention
- Always pass the codepage name string, e.g. 'UTF-8' or 'ISO-8859-1'.
- Remember decode failures return false; only wrong argument counts throw.
- Do not pass extra options arguments.
When it happens
Trigger: Calling isCodepage(data) with one argument, or isCodepage(data, 'UTF-8', extra) with three, from JavaScript in a Kettle script step.
Common situations: Forgetting the codepage name and relying on a default that does not exist; passing options objects as a third argument.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The function call date2str requires 1, 2, 3, or 4 arguments.
- The function call dateAdd requires 3 arguments.
- The function call escapeHtml requires 1 argument.
- The function call escapeSQL requires 1 argument.
- The function call escapeXml requires 1 argument.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/8053e6f4c0e3ff85.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:734
if ( ArgList.length == 2 ) {
try {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return undefinedValue;
}
String strValueToCheck = (String) ArgList[0];
String strCodePage = (String) ArgList[1];
byte[] bytearray = strValueToCheck.getBytes();
CharsetDecoder d = Charset.forName( strCodePage ).newDecoder();
CharBuffer r = d.decode( ByteBuffer.wrap( bytearray ) );
r.toString();
bRC = true;
} catch ( Exception e ) {
bRC = false;
}
} else {
throw new RuntimeException( "The function call isCodepage requires 2 arguments." );
}
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." );
}View on GitHub (pinned to f3058517a1)