{"record":{"id":"32a050d37cedd979","repo":"pentaho/pentaho-kettle","slug":"switchcase-log-unabletoconvertvalue","errorCode":"SwitchCase.Log.UnableToConvertValue","errorMessage":"SwitchCase.Log.UnableToConvertValue","messagePattern":"SwitchCase\\.Log\\.UnableToConvertValue","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/switchcase/SwitchCase.java","lineNumber":199,"sourceCode":"        }\n\n        try {\n          Object value =\n            data.valueMeta.convertDataFromString(\n              target.caseValue, data.stringValueMeta, null, null, ValueMetaInterface.TRIM_TYPE_NONE );\n\n          // If we have a value and a rowset, we can store the combination in the map\n          //\n          if ( data.valueMeta.isNull( value ) ) {\n            data.nullRowSetSet.add( rowSet );\n          } else {\n            // could not use byte[] as key in Maps, so we need to convert it to his specific hashCode for future\n            // comparisons\n            value = prepareObjectType( value );\n            data.outputMap.put( value, rowSet );\n          }\n        } catch ( Exception e ) {\n          throw new KettleException( BaseMessages.getString(\n            PKG, \"SwitchCase.Log.UnableToConvertValue\", target.caseValue ), e );\n        }\n      }\n\n      if ( meta.getDefaultTargetStep() != null ) {\n        RowSet rowSet = findOutputRowSet( meta.getDefaultTargetStep().getName() );\n        if ( rowSet != null ) {\n          data.defaultRowSetSet.add( rowSet );\n          if ( data.nullRowSetSet.isEmpty() ) {\n            data.nullRowSetSet.add( rowSet );\n          }\n        }\n      }\n    } catch ( Exception e ) {\n      throw new KettleException( e );\n    }\n  }\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/switchcase/SwitchCase.java#L181-L217","documentation":"KettleException thrown by SwitchCase.createOutputValueMapping when converting the configured case value (stored as a string in metadata) to the data type of the switch field fails via data.valueMeta.convertDataFromString, or when the subsequent value preparation throws. The message includes the offending case value. This makes the case value and the field type mismatch fatal at startup of the step.","triggerScenarios":"A case value like 'abc' against a numeric/Integer switch field, malformed dates ('13/45/2024') against a Date field, locale-dependent number formats, or empty case-value strings against non-string fields — any Exception from convertDataFromString inside the per-target loop.","commonSituations":"Changing the switch field's data type upstream (e.g., String to Integer) without updating case values; entering dates in a format not matching the field's conversion mask; copy-pasting case values with stray spaces; locale differences between designer and server JVMs.","solutions":["Make each case value exactly convertible to the switch field's data type (e.g., '1' not 'one' for Integer fields).","Align date/number conversion masks in the field's value metadata with the format of the case values.","Trim spaces and normalize the format of case values in the dialog.","If the field type changed upstream, update the field metadata and all case values, then re-save."],"exampleFix":"// before: non-numeric case value on an Integer field\ncaseValue = \"one\";\n// after\ncaseValue = \"1\";","handlingStrategy":"validation","validationCode":"// check each case value converts to the switch field's type\nValueMetaInterface vm = inputRowMeta.getValueMeta( inputRowMeta.indexOfValue( meta.getFieldname() ) );\nfor ( SwitchCaseTarget t : meta.getCaseTargets() ) {\n  try { vm.convertDataFromString( t.getCaseValue(), new ValueMetaString( \"v\" ), null, null, 0 ); }\n  catch ( Exception e ) { throw new KettleException( \"Case value not convertible: \" + t.getCaseValue(), e ); }\n}","typeGuard":null,"tryCatchPattern":"try { run(); } catch ( KettleException e ) { if ( e.getMessage().contains( \"UnableToConvertValue\" ) ) log.error( \"Fix case value formats to match field type\" ); throw e; }","preventionTips":["Match case value format to the field's conversion mask (dates, numbers).","Trim whitespace from case values.","Align JVM locales between designer and server.","Re-enter case values after changing the switch field's data type."],"tags":["kettle","switch-case","type-conversion","transform"],"backgroundTag":"invalid-argument-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"}