{"record":{"id":"b66522d07e7463a9","repo":"pentaho/pentaho-kettle","slug":"the-function-call-lpad-requires-3-arguments-b66522","errorCode":null,"errorMessage":"The function call lpad requires 3 arguments.","messagePattern":"The function call lpad requires 3 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":828,"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) Context.getUndefinedValue();\n        }\n        String valueToPad = Context.toString( ArgList[0] );\n        String filler = Context.toString( ArgList[1] );\n        int size = (int) Context.toNumber( ArgList[2] );\n\n        while ( valueToPad.length() < size ) {\n          valueToPad = filler + valueToPad;\n        }\n        return valueToPad;\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call lpad requires 3 arguments.\" );\n    }\n    return null;\n  }\n\n  public static String rpad( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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) Context.getUndefinedValue();\n        }\n        String valueToPad = Context.toString( ArgList[0] );\n        String filler = Context.toString( ArgList[1] );\n        int size = (int) Context.toNumber( ArgList[2] );\n\n        while ( valueToPad.length() < size ) {","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L810-L846","documentation":"The lpad() function in the JavaScript step pads a string on the left to a given size using a filler string. It requires exactly 3 arguments (value, size, filler); if the call throws for any reason — most commonly an argument count mismatch — it reports this error. Note the message is misleading: any exception in the body also produces it.","triggerScenarios":"Calling lpad() in a modified JavaScript step with fewer than 3 arguments (e.g. lpad(field, 5)), or with arguments whose conversion fails (null value, non-numeric size).","commonSituations":"Scripts written against a different signature (some libraries' lpad takes only 2 args with a default filler), copy-pasted SQL LPAD with optional filler, or a null incoming field value.","solutions":["Call lpad() with exactly 3 arguments: value, target size, filler string.","Null-check the value before padding.","Verify the size argument is a number and the filler is a non-empty string.","If a 2-argument call is desired, add the filler explicitly, e.g. lpad(field, 5, '0')."],"exampleFix":"// before\nvar padded = lpad(myField, 10);\n// after\nvar padded = lpad(myField, 10, '0');","handlingStrategy":"validation","validationCode":"if (myField == null) throw 'lpad: value is null';\nvar padded = lpad(String(myField), 10, '0');","typeGuard":"function canLpad(v, size, filler) { return v != null && typeof size === 'number' && typeof filler === 'string' && filler.length > 0; }","tryCatchPattern":"try { var padded = lpad(String(myField), 10, '0'); } catch (e) { var padded = String(myField); }","preventionTips":["Always supply all 3 arguments: value, size, filler","Remember the error message is generic — any lpad failure shows it","Coerce value with String() and size with a numeric literal","Test scripts in a dry-run transformation before production"],"tags":["javascript","rhino","string-functions"],"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"}