{"record":{"id":"2754924cc07c9e5d","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmod-log-unexpectedeerror","errorCode":null,"errorMessage":"ScriptValuesMod.Log.UnexpectedeError","messagePattern":"ScriptValuesMod\\.Log\\.UnexpectedeError","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java","lineNumber":377,"sourceCode":"            Scriptable jsarg = Context.toObject( data.values_used[ i ], data.scope );\n            data.scope.put( valueMeta.getName(), data.scope, jsarg );\n          } else {\n            Object normalStorageValueData = valueMeta.convertToNormalStorageType( valueData );\n            Scriptable jsarg;\n            if ( normalStorageValueData != null ) {\n              jsarg = Context.toObject( normalStorageValueData, data.scope );\n            } else {\n              jsarg = null;\n            }\n            data.scope.put( valueMeta.getName(), data.scope, jsarg );\n          }\n        }\n\n        // also add the meta information for the hole row\n        Scriptable jsrowMeta = Context.toObject( rowMeta, data.scope );\n        data.scope.put( \"rowMeta\", data.scope, jsrowMeta );\n      } catch ( Exception e ) {\n        throw new KettleValueException( BaseMessages.getString( PKG, \"ScriptValuesMod.Log.UnexpectedeError\" ), e );\n      }\n\n      // Executing our Script\n      data.script.exec( data.cx, data.scope );\n\n      if ( bFirstRun ) {\n        bFirstRun = false;\n        // Check if we had a Transformation Status\n        Object tran_stat = data.scope.get( \"trans_Status\", data.scope );\n        if ( tran_stat != ScriptableObject.NOT_FOUND ) {\n          bWithTransStat = true;\n          if ( log.isDetailed() ) {\n            logDetailed( ( \"tran_Status found. Checking transformation status while script execution.\" ) );\n          }\n        } else {\n          if ( log.isDetailed() ) {\n            logDetailed( ( \"No tran_Status found. Transformation status checking not available.\" ) );\n          }","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L359-L395","documentation":"Generic wrapper thrown when preparing the JavaScript scope for a row fails unexpectedly. Before executing the script, addValues() converts the incoming row values and the row metadata (rowMeta) into scriptable objects via Context.toObject and puts them into the scope; any Exception in that preparation is wrapped as a KettleValueException with the 'Unexpected error' message. The chained cause holds the real problem.","triggerScenarios":"Context.toObject(rowMeta, data.scope) or scope.put(\"rowMeta\", ...) throws during row processing in addValues() from processRow — e.g. Rhino fails to wrap a value or the scope is in an invalid state.","commonSituations":"Rows containing exotic/binary field types that Rhino cannot wrap, corrupted row metadata after upstream type changes, or internal Context state problems in long-running transformations.","solutions":["Inspect the chained cause to find which field or operation failed","Check the row's field types upstream; convert exotic types (binary/serialized) to strings or numbers before this step","Restart the transformation if the scripting Context became corrupted mid-run","Ensure upstream steps define stable, well-typed fields for every row","Update Kettle/Rhino to a version fixing scope-wrapping issues"],"exampleFix":"// before: passing raw binary field into script step\n// upstream Select Values passes TYPE_BINARY 'payload'\n// after: convert to string before the JavaScript step\n// (upstream) SelectValues metadata change: payload -> TYPE_STRING","handlingStrategy":"try-catch","validationCode":"// Ensure upstream fields are simple, typed values before the script step\n// Preview the previous step and confirm no TYPE_BINARY / serialized fields reach the script","typeGuard":null,"tryCatchPattern":"try {\n  processRow();\n} catch ( KettleValueException e ) {\n  logError( \"Row scope preparation failed for row: \" + e.getCause(), e );\n  putError(...); // route the row to error handling instead of failing the transform\n}","preventionTips":["Convert binary/complex fields to strings or numbers upstream","Keep row metadata stable across transformation edits","Enable step error handling to capture bad rows instead of aborting"],"tags":["javascript","rhino","row-processing","scope"],"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"}