{"record":{"id":"af0d9261f83a3d5a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-lpad-requires-3-arguments","errorCode":null,"errorMessage":"The function call lpad requires 3 arguments.","messagePattern":"The function call lpad requires 3 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":798,"sourceCode":"    // (String valueToPad, String filler, int size) {\n    try {\n      if ( ArgList.length == 3 ) {\n        if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return (String) undefinedValue;\n        }\n        String valueToPad = (String) ArgList[0];\n        String filler = (String) ArgList[1];\n        int size = (Integer) ArgList[2];\n\n        while ( valueToPad.length() < size ) {\n          valueToPad = filler + valueToPad;\n        }\n        return valueToPad;\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"The function call lpad requires 3 arguments.\" );\n    }\n    return null;\n  }\n\n  public static String rpad( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 3 ) {\n        if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n          return (String) undefinedValue;\n        }\n        String valueToPad = (String) ArgList[0];\n        String filler = (String) ArgList[1];\n        int size = (Integer) ArgList[2];\n\n        while ( valueToPad.length() < size ) {","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L780-L816","documentation":"lpad() left-pads a string to a target size with a filler string. It validates ArgList.length == 3 inside a try block; if the call does not have exactly three arguments (or another exception occurs), the catch rethrows this RuntimeException and the function returns null.","triggerScenarios":"Calling lpad(value, size) or lpad(value) in a Script step, or a call whose inner processing throws (non-numeric size, non-string filler), causing the catch block to fire with this message.","commonSituations":"Forgetting the pad character argument when porting SQL LPAD knowledge that allows a default; passing a variable number of arguments from conditional script code.","solutions":["Call lpad with exactly three arguments: lpad(value, size, filler).","Ensure size is a positive integer and filler is a string.","Check the script step log for this message and fix the argument count in the JS source.","If a default filler is desired, pass it explicitly, e.g. lpad(v, 5, \" \")."],"exampleFix":"// before\nvar padded = lpad(value, 5);\n// after\nvar padded = lpad(value, 5, \"0\");","handlingStrategy":"validation","validationCode":"if (value != null && typeof size === \"number\" && size > 0) { var padded = lpad(value, size, filler); }","typeGuard":"function canLpad(v, size, filler) { return v != null && typeof size === \"number\" && size > 0 && filler != null && String(filler).length > 0; }","tryCatchPattern":"try {\n  var padded = lpad(value, size, filler);\n  if (padded === null) { /* argument-count failure path */ }\n} catch (e) {\n  Logger.LogBasic(\"lpad failed: \" + e.message);\n  padded = value;\n}","preventionTips":["Pass all three arguments: value, size, filler.","Keep size a positive integer.","Ensure filler is a non-empty string.","Beware: on failure the function also returns null — check the result."],"tags":["javascript","script-step","argument-count","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"}