{"record":{"id":"8053e6f4c0e3ff85","repo":"pentaho/pentaho-kettle","slug":"the-function-call-iscodepage-requires-2-arguments","errorCode":null,"errorMessage":"The function call isCodepage requires 2 arguments.","messagePattern":"The function call isCodepage requires 2 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":734,"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 undefinedValue;\n        }\n        String strValueToCheck = (String) ArgList[0];\n        String strCodePage = (String) 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 new RuntimeException( \"The function call isCodepage requires 2 arguments.\" );\n    }\n    return Boolean.valueOf( bRC );\n  }\n\n  public static String ltrim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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) undefinedValue;\n        }\n        String strValueToTrim = (String) ArgList[0];\n        return strValueToTrim.replaceAll( \"^\\\\s+\", \"\" );\n      } else {\n        throw new RuntimeException( \"The function call ltrim requires 1 argument.\" );\n      }","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L716-L752","documentation":"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.","triggerScenarios":"Calling isCodepage(data) with one argument, or isCodepage(data, 'UTF-8', extra) with three, from JavaScript in a Kettle script step.","commonSituations":"Forgetting the codepage name and relying on a default that does not exist; passing options objects as a third argument.","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."],"exampleFix":"// before\nvar ok = isCodepage(rawBytes);\n// after\nvar ok = isCodepage(rawBytes, 'ISO-8859-1');","handlingStrategy":"validation","validationCode":"if (arguments.length !== 2 || typeof codepage !== 'string') {\n  throw new Error('isCodepage requires exactly 2 arguments: (data, codepage)');\n}\nvar ok = isCodepage(data, codepage);","typeGuard":"function isCodepageCall(d, c) { return d != null && typeof c === 'string' && c.length > 0; }","tryCatchPattern":"try {\n  var ok = isCodepage(data, codepage);\n} catch (e) {\n  if (String(e.message).indexOf('requires 2 arguments') !== -1) {\n    throw new Error('Call isCodepage as isCodepage(data, codepageName)');\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["javascript","argument-count","encoding","pentaho-kettle"],"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"}