{"record":{"id":"0a1c7515ce5d6f71","repo":"pentaho/pentaho-kettle","slug":"e-getmessage-scriptaddedfunctions","errorCode":null,"errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1425,"sourceCode":"        // break;\n      case 3:\n        try {\n          if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {\n            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {\n            return undefinedValue;\n          }\n          String sArg1 = (String) ArgList[0];\n          String sArg2 = (String) ArgList[1];\n          String sArg3 = (String) ArgList[2];\n          if ( sArg3.length() == 2 ) {\n            DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );\n            DecimalFormat formatter = new DecimalFormat( sArg2, dfs );\n            dRC = ( formatter.parse( sArg1 ) ).doubleValue();\n            return new Double( dRC );\n          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( e.getMessage() );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call str2num requires 1, 2, or 3 arguments.\" );\n    }\n    return new Double( dRC );\n  }\n\n  public static Object isNum( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1407-L1443","documentation":"ScriptAddedFunctions.str2num parses a string into a number using java.text.DecimalFormat with an optional pattern and locale. Any exception during parsing or pattern/locale construction is rethrown as a RuntimeException whose message is only e.getMessage(), so the original exception type and stack trace are lost. This typically fires when the input string is not parseable as a number under the given pattern/locale.","triggerScenarios":"Calling str2num(s) / str2num(s, pattern) / str2num(s, pattern, locale) inside a JavaScript (JS) transformation step where s cannot be parsed by DecimalFormat with the supplied pattern and locale (e.g. '12,5' with pattern '#,###' in an English locale).","commonSituations":"Locale mismatches (decimal comma vs dot), wrong DecimalFormat pattern strings, strings containing currency symbols or whitespace, null/undefined values passed from the JS step.","solutions":["Verify the string exactly matches the DecimalFormat pattern and locale (e.g. use pattern '#,##0.00' with locale 'en' for '1,234.56').","Normalize the input string first (trim, fix decimal separator) before calling str2num.","Pre-check with isNum(str) in the script before converting.","Catch the RuntimeException in the script and return a default value instead of failing the row."],"exampleFix":"// before\nvar n = str2num('12,5', '#,###', 'en'); // throws\n// after\nvar n = isNum('12,5') ? str2num('12,5', '#,##0.0', 'en') : 0;","handlingStrategy":"validation","validationCode":"function safeStr2num(v, pattern, locale) {\n  if (v === null || v === undefined) return null;\n  var s = String(v).trim();\n  if (!/^[+-]?[0-9.,eE+-]+$/.test(s)) return null;\n  try { return str2num(s, pattern || '#,##0.########', locale || 'en'); }\n  catch (e) { return null; }\n}","typeGuard":"function isNumericString(v) {\n  return typeof v === 'string' && v.trim() !== '' && !isNaN(Number(v.trim()));\n}","tryCatchPattern":"try {\n  var n = str2num(s, pattern, locale);\n} catch (e) {\n  // log e.message, route row to error handling / default value\n  var n = null;\n}","preventionTips":["Call isNum() before str2num() in scripts.","Match the DecimalFormat pattern and locale to the actual string format (decimal comma vs dot).","Trim and normalize numeric strings before conversion.","Handle failures per-row instead of letting the step abort."],"tags":["java","pdi","number-parsing","scripting"],"backgroundTag":"invalid-argument-format","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"}