{"record":{"id":"3077712b76fbed17","repo":"pentaho/pentaho-kettle","slug":"throw-new-kettlevalueexception-e","errorCode":null,"errorMessage":"throw new KettleValueException( e );","messagePattern":"throw new KettleValueException\\( e \\);","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java","lineNumber":196,"sourceCode":"              data.returnType[i] = FormulaData.RETURN_TYPE_BOOLEAN;\n              if ( fn.getValueType() != ValueMetaInterface.TYPE_BOOLEAN ) {\n                throw new KettleValueException( \"Please specify a Boolean type for field [\"\n                  + fn.getFieldName() + \"] as a result of formula [\" + fn.getFormula() + \"]\" );\n              }\n            } else {\n              data.returnType[i] = FormulaData.RETURN_TYPE_STRING;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_STRING );\n            }\n          }\n\n          int realIndex = ( data.replaceIndex[i] < 0 ) ? tempIndex++ : data.replaceIndex[i];\n          outputRowData[realIndex] = getReturnValue( formulaResult, data.returnType[i], realIndex, fn );\n        }\n      }\n\n      return outputRowData;\n    } catch ( Throwable e ) {\n      throw new KettleValueException( e );\n    }\n  }\n\n  protected Object getReturnValue( Object formulaResult, int returnType, int realIndex, FormulaMetaFunction fn )\n    throws KettleException {\n    if ( formulaResult == null ) {\n      return null;\n    }\n    Object value = null;\n    switch ( returnType ) {\n      case FormulaData.RETURN_TYPE_STRING:\n        if ( fn.isNeedDataConversion() ) {\n          value = convertDataToTargetValueMeta( realIndex, formulaResult );\n        } else {\n          value = formulaResult.toString();\n        }\n        break;\n      case FormulaData.RETURN_TYPE_NUMBER:","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java#L178-L214","documentation":"Catch-all wrapper in Formula.calcFields(): any Throwable escaping formula setup, evaluation, or result conversion is rethrown as a KettleValueException with the original as cause. The 'message' shown is just the wrap site; the real cause is in getCause().","triggerScenarios":"Any runtime failure inside calcFields not already thrown explicitly — e.g. formula engine parse errors, class loading issues for the reporting formula library, unexpected result types in getReturnValue().","commonSituations":"Malformed formula syntax accepted at design time but failing per row; missing pentaho-reporting formula engine jars at runtime; type conversion failure in getReturnValue().","solutions":["Log and inspect the 'Caused by' of the KettleValueException for the real error.","Validate the formula expression syntax in the formula editor before running.","Ensure all pentaho-reporting-libformula dependencies are on the classpath.","Check the specific result type handling if the formula output type changed recently."],"exampleFix":"// before\nString f = \"SUM([a\"\n// after\nString f = \"SUM([a])\"; // balanced, parseable formula","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { output = calcFields(row); } catch (KettleValueException e) { Throwable root = e; while (root.getCause() != null) root = root.getCause(); log.error(\"Formula failure root cause: \" + root.getMessage(), root); throw e; }","preventionTips":["Always inspect the root cause chain of this wrapper exception","Validate formula syntax before running","Keep formula library jars complete on the classpath","Test formulas with sample data via the preview feature"],"tags":["formula","wrapper-exception","runtime"],"backgroundTag":"internal-invariant-violation","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"}