{"record":{"id":"9d7e77df092de506","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmod-log-couldnotadddefaultconstants","errorCode":null,"errorMessage":"ScriptValuesMod.Log.CouldNotAddDefaultConstants","messagePattern":"ScriptValuesMod\\.Log\\.CouldNotAddDefaultConstants","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java","lineNumber":288,"sourceCode":"            ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class,\n            ScriptableObject.DONTENUM );\n        } catch ( Exception ex ) {\n          // System.out.println(ex.toString());\n          throw new KettleValueException( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Log.CouldNotAddDefaultFunctions\" ), ex );\n        }\n\n        // Adding some Constants to the JavaScript\n        try {\n\n          data.scope.put( \"SKIP_TRANSFORMATION\", data.scope, Integer.valueOf( SKIP_TRANSFORMATION ) );\n          data.scope.put( \"ABORT_TRANSFORMATION\", data.scope, Integer.valueOf( ABORT_TRANSFORMATION ) );\n          data.scope.put( \"ERROR_TRANSFORMATION\", data.scope, Integer.valueOf( ERROR_TRANSFORMATION ) );\n          data.scope.put( \"CONTINUE_TRANSFORMATION\", data.scope, Integer.valueOf( CONTINUE_TRANSFORMATION ) );\n\n        } catch ( Exception ex ) {\n          // System.out.println(\"Exception Adding the Constants \" + ex.toString());\n          throw new KettleValueException( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Log.CouldNotAddDefaultConstants\" ), ex );\n        }\n\n        try {\n          // Checking for StartScript\n          if ( strStartScript != null && strStartScript.length() > 0 ) {\n            Script startScript = data.cx.compileString( strStartScript, \"trans_Start\", 1, null );\n            startScript.exec( data.cx, data.scope );\n            if ( log.isDetailed() ) {\n              logDetailed( ( \"Start Script found!\" ) );\n            }\n          } else {\n            if ( log.isDetailed() ) {\n              logDetailed( ( \"No starting Script found!\" ) );\n            }\n          }\n        } catch ( Exception es ) {\n          // System.out.println(\"Exception processing StartScript \" + es.toString());","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L270-L306","documentation":"Thrown by ScriptValuesMod.addValues() when registering the built-in transformation constants (ABORT_TRANSFORMATION, ERROR_TRANSFORMATION, CONTINUE_TRANSFORMATION) into the JavaScript scope fails. The step wraps Context/Scope initialization in a try-catch and rethrows any Exception as a KettleValueException with this localized message, chaining the original cause. It means the Rhino scripting environment could not be seeded with default constants before running the user script.","triggerScenarios":"An Exception (e.g. Rhino ContextException or illegal scope state) is raised while calling data.scope.put(...) for ABORT_TRANSFORMATION / ERROR_TRANSFORMATION / CONTINUE_TRANSFORMATION inside addValues(), invoked from processRow during step initialization of the Modified Java Script Value step.","commonSituations":"Corrupted or re-entered Rhino Context (Context.enter/exit imbalance), a non-scriptable or already-finalized scope object, or an unexpected internal Rhino exception during scope property definition; typically seen after JVM/Rhino version changes rather than by user misconfiguration.","solutions":["Read the chained cause ('Caused by') of the KettleValueException to identify the underlying Rhino error","Restart the transformation/Kettle JVM to reset the scripting Context","Check for mismatched Rhino/Mozilla JavaScript library versions on the classpath (duplicate js.jar)","Verify the step is not being initialized concurrently/re-entrantly with a shared scope","Upgrade to a Pentaho/Kettle version with fixed script values mod initialization"],"exampleFix":"// before: catching generic Exception hides the real cause\nthrow new KettleValueException( BaseMessages.getString( PKG, \"ScriptValuesMod.Log.CouldNotAddDefaultConstants\" ), ex );\n// after (user side): inspect the full cause chain\ntry {\n  step.processRow( meta, data );\n} catch ( KettleValueException e ) {\n  logError( \"Script init failed\", e ); // full stacktrace shows Rhino root cause\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Before running, ensure no duplicate Rhino js jars and a fresh JVM\n// e.g. in a shell: find $KETTLE_CLASSPATH -name 'js*.jar' | sort  # should list at most one","typeGuard":null,"tryCatchPattern":"try {\n  step.processRow( meta, data );\n} catch ( KettleValueException e ) {\n  Throwable root = e;\n  while ( root.getCause() != null ) { root = root.getCause(); }\n  logError( \"Script constants init failed, root cause: \" + root, e );\n  throw e;\n}","preventionTips":["Keep exactly one Rhino/JavaScript library version on the classpath","Restart the JVM after upgrading Kettle or scripting libraries","Don't share or re-enter scripting scopes across transformations concurrently"],"tags":["javascript","rhino","step-initialization","scripting"],"backgroundTag":"module-init-failed","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"}