{"record":{"id":"4b8c9832fd66b6d4","repo":"pentaho/pentaho-kettle","slug":"script-log-couldnotadddefaultconstants","errorCode":"Script.Log.CouldNotAddDefaultConstants","errorMessage":"Script.Log.CouldNotAddDefaultConstants","messagePattern":"Script\\.Log\\.CouldNotAddDefaultConstants","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java","lineNumber":247,"sourceCode":"        // ScriptValuesAddedFunctions.class, ScriptableObject.DONTENUM);\n        // } catch (Exception ex) {\n        // // System.out.println(ex.toString());\n        // throw new KettleValueException(BaseMessages.getString(PKG, \"Script.Log.CouldNotAddDefaultFunctions\"), ex);\n        // }\n        // ;\n\n        // Adding some Constants to the JavaScript\n        try {\n\n          data.scope.put( \"SKIP_TRANSFORMATION\", Integer.valueOf( SKIP_TRANSFORMATION ) );\n          data.scope.put( \"ABORT_TRANSFORMATION\", Integer.valueOf( ABORT_TRANSFORMATION ) );\n          data.scope.put( \"ERROR_TRANSFORMATION\", Integer.valueOf( ERROR_TRANSFORMATION ) );\n          data.scope.put( \"CONTINUE_TRANSFORMATION\", Integer.valueOf( CONTINUE_TRANSFORMATION ) );\n\n        } catch ( Exception ex ) {\n          // System.out.println(\"Exception Adding the Constants \" +\n          // ex.toString());\n          throw new KettleValueException(\n            BaseMessages.getString( PKG, \"Script.Log.CouldNotAddDefaultConstants\" ), ex );\n        }\n\n        try {\n          // Checking for StartScript\n          if ( strStartScript != null && strStartScript.length() > 0 ) {\n            CompiledScript startScript = ( (Compilable) data.cx ).compile( strStartScript );\n            startScript.eval( 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 \" +","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java#L229-L265","documentation":"Thrown in Script.addValues when adding the default constants to the JavaScript scope fails. The step puts well-known constants (e.g. SKIP_TRANSFORMATION, ERROR_TRANSFORMATION, CONTINUE_TRANSFORMATION) into the Scriptable scope; any Exception raised while doing so is wrapped in a KettleValueException with this message. It indicates scope/context initialization failed, usually due to an underlying Rhino/JS engine problem.","triggerScenarios":"addValues (called from processRow) executing data.scope.put(\"_TRANSFORMATION_...\") for the default constants and the underlying scope.put throwing any Exception (caught as ex).","commonSituations":"Rhino/native JS engine version incompatibilities where the shared scope is sealed or in an unexpected state; the context/scope was already closed from a previous failed row; custom plugins altering the scope.","solutions":["Restart the transformation/JVM to get a fresh scripting context and scope.","Check the JS engine version bundled with your Pentaho/Kettle distribution and align with the supported version.","Inspect the wrapped cause (ex) for the underlying scripting-engine error and fix accordingly.","Verify no custom plugin or jar is replacing/conflicting with the bundled Rhino classes."],"exampleFix":"// before: engine scope shared across runs becomes unusable after an error\n// after: ensure a fresh scope per run / restart transformation after a script error\n// (operational fix — no code change available in user space)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  step.processRow();\n} catch (KettleValueException e) {\n  if (e.getMessage().contains(\"CouldNotAddDefaultConstants\")) {\n    logError(\"JS scope broken; restarting transformation\", e);\n    // restart transformation / new scripting context, then retry\n  } else { throw e; }\n}","preventionTips":["Restart the transformation after any scripting error instead of reusing a broken scope.","Use the Rhino/JS engine version bundled and supported by your Pentaho distribution.","Avoid plugins that replace scripting-engine jars in lib/.","Keep one script context per transformation run."],"tags":["kettle","javascript","rhino","script-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"}