{"record":{"id":"6f25086e8f899e6d","repo":"pentaho/pentaho-kettle","slug":"the-function-call-abs-requires-1-argument","errorCode":null,"errorMessage":"The function call abs requires 1 argument.","messagePattern":"The function call abs requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":375,"sourceCode":"  }\n\n  public static Object abs( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        } else {\n          return new Double( Math.abs( (Double) ArgList[0] ) );\n        }\n      } catch ( Exception e ) {\n        return null;\n      }\n    } else {\n      throw new RuntimeException( \"The function call abs requires 1 argument.\" );\n    }\n  }\n\n  public static Object ceil( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        } else {\n          return new Double( Math.ceil( (Double) ArgList[0] ) );\n        }\n      } catch ( Exception e ) {\n        return null;\n      }\n    } else {","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L357-L393","documentation":"The added abs function takes exactly 1 numeric argument and returns its absolute value as a Double. Wrong argument count throws RuntimeException; a non-numeric value inside the correct arity is swallowed and returns null.","triggerScenarios":"Calling abs() with no arguments or abs(x, y) with two arguments in a Script step.","commonSituations":"Confusing with Math.abs usage patterns; expecting multiple-value support; generated scripts emitting extra arguments.","solutions":["Call abs with exactly one numeric argument","Ensure the argument is a Number (cast/parse in JS) to avoid null return","Wrap in try/catch for dynamic arity"],"exampleFix":"// before\nvar v = abs(x, 0);\n// after\nvar v = abs(x);","handlingStrategy":"validation","validationCode":"// JS in Script step\nif (arguments.length !== 1 || typeof arguments[0] !== 'number') {\n  throw new Error('abs expects exactly one numeric argument');\n}\nvar v = abs(x);","typeGuard":"// JS\nfunction isSingleNumber(args) {\n  return args.length === 1 && typeof args[0] === 'number' && !isNaN(args[0]);\n}","tryCatchPattern":"try {\n  var v = abs(x);\n  if (v === null) { /* non-numeric input case */ }\n} catch (e) {\n  Logger.logError('abs failed: ' + e.message);\n  v = null;\n}","preventionTips":["Parse strings to numbers before calling abs","Remember null (not an exception) signals bad input within correct arity","Avoid passing extra sentinel arguments"],"tags":["kettle","javascript","arity","math"],"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"}