{"record":{"id":"518db13b6e9a79c3","repo":"pentaho/pentaho-kettle","slug":"the-function-call-iscodepage-requires-2-arguments-518db1","errorCode":null,"errorMessage":"The function call isCodepage requires 2 arguments.","messagePattern":"The function call isCodepage requires 2 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":764,"sourceCode":"    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return Context.getUndefinedValue();\n        }\n        String strValueToCheck = Context.toString( ArgList[0] );\n        String strCodePage = Context.toString( ArgList[1] );\n        byte[] bytearray = strValueToCheck.getBytes();\n        CharsetDecoder d = Charset.forName( strCodePage ).newDecoder();\n        CharBuffer r = d.decode( ByteBuffer.wrap( bytearray ) );\n        r.toString();\n        bRC = true;\n      } catch ( Exception e ) {\n        bRC = false;\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call isCodepage requires 2 arguments.\" );\n    }\n    return Boolean.valueOf( bRC );\n  }\n\n  public static String ltrim( 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 ltrim requires 1 argument.\" );\n      }","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L746-L782","documentation":"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.","triggerScenarios":"Calling isCodepage('text') without the codepage name, or adding extra arguments such as a default-value flag.","commonSituations":"Ported scripts from other engines where isCodepage took one argument; confusion with Java's Charset API wrappers.","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"],"exampleFix":"// before\nvar ok = isCodepage(value);\n// after\nvar ok = isCodepage(value, 'ISO-8859-1');","handlingStrategy":"validation","validationCode":"if (arguments.length !== 2) throw new Error('isCodepage(str, codepage) requires 2 arguments');","typeGuard":null,"tryCatchPattern":"try { var ok = isCodepage(str, cp); } catch (e) { if (String(e).indexOf('requires 2 arguments') >= 0) { /* add codepage arg */ } }","preventionTips":["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"],"tags":["javascript","kettle","encoding","argument-count"],"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"}