{"record":{"id":"6cd293911614631d","repo":"pentaho/pentaho-kettle","slug":"e-getmessage-scriptvaluesaddedfunctions","errorCode":null,"errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1460,"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 Context.getUndefinedValue();\n          }\n          String sArg1 = Context.toString( ArgList[0] );\n          String sArg2 = Context.toString( ArgList[1] );\n          String sArg3 = Context.toString( 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 Context.reportRuntimeError( e.getMessage() );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call str2num requires 1, 2, or 3 arguments.\" );\n    }\n    return new Double( dRC );\n  }\n\n  public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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 Context.getUndefinedValue();\n        }","sourceCodeStart":1442,"sourceCodeEnd":1478,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1442-L1478","documentation":"This is the 3-argument branch of the str2num function (value, format pattern, locale). It creates a DecimalFormat with DecimalFormatSymbols built from EnvUtil.createLocale on the lowercased third argument, then parses the value. Any exception during locale resolution, pattern compilation, or parsing is caught and rethrown verbatim as e.getMessage(), so the reported message is the underlying cause's message rather than a descriptive prefix.","triggerScenarios":"str2num('1,234.56', '#,##0.00', 'us') with an unknown/invalid locale string; str2num('abc', '#,##0.00', 'en') where the value doesn't parse under the given locale's symbols; a null value combined with a locale argument.","commonSituations":"Converting multi-region source data in one transformation, passing an empty or misspelled locale tag ('deutsch' instead of 'de'), or format/value mismatch when concatenating fields from different file formats.","solutions":["Read the thrown e.getMessage() to identify whether the cause is the locale, the pattern, or the value","Use a valid ISO locale code (language, optionally country) as the third argument, e.g. str2num(v, '#,##0.00', 'en')","Confirm the value parses under the locale's decimal separator (comma vs dot)","Validate with isNum(v) before calling str2num","Null-check the field: a missing incoming field surfaces here as a parse/NPE"],"exampleFix":"// before\nvar n = str2num('1.234,56', '#,##0.00', 'en'); // '1.234,56' doesn't parse with EN symbols\n// after\nvar n = str2num('1.234,56', '#,##0.00', 'de'); // match locale to data","handlingStrategy":"validation","validationCode":"function safeStr2numLocale(v, fmt, loc) {\n  if (v === null || v === undefined) return null;\n  if (!/^[a-z]{2}(_[A-Z]{2})?$/.test(loc)) return null;\n  return str2num(String(v).trim(), fmt, loc);\n}","typeGuard":"function isLocaleTag(s) { return typeof s === 'string' && /^[a-z]{2}(_[A-Z]{2})?$/.test(s); }","tryCatchPattern":"try {\n  var n = str2num(value, '#,##0.00', 'de');\n} catch (e) {\n  // this branch rethrows the raw cause message — log it verbatim\n  Logger.LogError('str2num(3-arg) failed: ' + e.message);\n  n = null;\n}","preventionTips":["Validate the locale string against ISO codes before calling","Keep the value's separators consistent with the chosen locale","Test both comma-decimal and dot-decimal samples when locales change","Don't rely on this overload's message content — it's the raw exception message","Sanitize the incoming field once, then convert"],"tags":["javascript","decimalformat","locale","number-parsing","pentaho"],"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"}