pentaho/pentaho-kettle · error
The function call isCodepage requires 2 arguments.
Error message
The function call isCodepage requires 2 arguments.
What it means
isCodepage tests whether a string can be encoded/decoded in a given codepage within Kettle's JavaScript step. It requires exactly 2 arguments: the string and the codepage name. With any other argument count it throws this RuntimeError; note that encoding failures inside the try block only set the result to false, they do not throw.
Solutions
- Call with exactly two arguments: isCodepage(myString, 'UTF-8')
- Quote the codepage name and use a valid charset identifier (e.g. 'ISO-8859-1', 'US-ASCII')
- Validate the string argument is defined before the call
Example fix
// before var ok = isCodepage(value); // after var ok = isCodepage(value, 'ISO-8859-1');
Defensive patterns
Strategy: validation
Validate before calling
if (arguments.length !== 2) throw new Error('isCodepage(str, codepage) requires 2 arguments'); Try / catch
try { var ok = isCodepage(str, cp); } catch (e) { if (String(e).indexOf('requires 2 arguments') >= 0) { /* add codepage arg */ } } Prevention
- Always supply the codepage name as a quoted string
- Use standard charset identifiers ('UTF-8','ISO-8859-1')
- Treat a false result as encoding failure - it is not thrown
When it happens
Trigger: Calling isCodepage('text') without the codepage name, or adding extra arguments such as a default-value flag.
Common situations: Ported scripts from other engines where isCodepage took one argument; confusion with Java's Charset API wrappers.
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 dateAdd requires 3 arguments.
- The function call dateDiff requires 3 arguments.
- The function call fillString requires 2 arguments.
- The function call fireToDB requires 2 arguments.
- The function call getFileExtension is not valid.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/518db13b6e9a79c3.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:764
if ( ArgList.length == 2 ) {
try {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return Context.getUndefinedValue();
}
String strValueToCheck = Context.toString( ArgList[0] );
String strCodePage = Context.toString( 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 Context.reportRuntimeError( "The function call isCodepage requires 2 arguments." );
}
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." );
}View on GitHub (pinned to f3058517a1)