{"record":{"id":"949fd54f069254ce","repo":"pentaho/pentaho-kettle","slug":"throw-new-kettlestepexception-e","errorCode":null,"errorMessage":"throw new KettleStepException( e );","messagePattern":"throw new KettleStepException\\( e \\);","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/FormulaMeta.java","lineNumber":159,"sourceCode":"  }\n\n  @Override\n  public void getFields( Bowl bowl, RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,\n    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {\n    for ( int i = 0; i < formula.length; i++ ) {\n      FormulaMetaFunction fn = formula[i];\n      if ( Utils.isEmpty( fn.getReplaceField() ) ) {\n        // Not replacing a field.\n        if ( !Utils.isEmpty( fn.getFieldName() ) ) {\n          // It's a new field!\n\n          try {\n            ValueMetaInterface v = ValueMetaFactory.createValueMeta( fn.getFieldName(), fn.getValueType() );\n            v.setLength( fn.getValueLength(), fn.getValuePrecision() );\n            v.setOrigin( name );\n            row.addValueMeta( v );\n          } catch ( Exception e ) {\n            throw new KettleStepException( e );\n          }\n        }\n      } else {\n        // Replacing a field\n        int index = row.indexOfValue( fn.getReplaceField() );\n        if ( index < 0 ) {\n          throw new KettleStepException( \"Unknown field specified to replace with a formula result: [\"\n            + fn.getReplaceField() + \"]\" );\n        }\n        // Change the data type etc.\n        //\n        ValueMetaInterface v = row.getValueMeta( index ).clone();\n        v.setLength( fn.getValueLength(), fn.getValuePrecision() );\n        v.setOrigin( name );\n        row.setValueMeta( index, v ); // replace it\n      }\n    }\n  }","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/FormulaMeta.java#L141-L177","documentation":"KettleStepException thrown in FormulaMeta.getFields() when ValueMetaFactory.createValueMeta() fails while building the step's output row metadata (e.g. unknown or invalid value type code). It wraps the underlying exception from metadata construction at design/initialization time.","triggerScenarios":"Calling getFields() on a FormulaMeta whose FormulaMetaFunction entries carry an invalid valueType (e.g. corrupted meta, unsupported type constant) so createValueMeta throws.","commonSituations":"Hand-edited .ktr XML with an out-of-range type attribute; transformation serialized by a newer Kettle version with a type the current one doesn't know; plugin version mismatch.","solutions":["Inspect the cause to find which field's value type is invalid.","Reopen the Formula step dialog and re-select the output Type for the offending formula row.","Open/save the transformation with a Kettle version matching the one that created it.","If hand-editing XML, use valid ValueMetaInterface type codes (e.g. 2=Number, 5=String)."],"exampleFix":"// before (ktr xml)\n<value_type>999</value_type>\n// after\n<value_type>5</value_type>","handlingStrategy":"try-catch","validationCode":"int knownTypes = ValueMetaInterface.TYPE_STRING | ValueMetaInterface.TYPE_NUMBER | /* ...valid mask... */ 0;\n// ensure fn.getValueType() is a supported ValueMetaInterface.TYPE_* before calling getFields()","typeGuard":null,"tryCatchPattern":"try { meta.getFields(row, name, info, target, repository, imeta); } catch (KettleStepException e) { log.error(\"Invalid value type in Formula meta: \" + e.getCause(), e); throw e; }","preventionTips":["Never hand-edit value_type codes in .ktr XML","Match the Kettle version used to author transformations","Re-select output types in the dialog after upgrades"],"tags":["metadata","value-type","formula"],"backgroundTag":"invalid-enum-value","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"}