{"record":{"id":"32adb1a76b6c5e6f","repo":"mrdoob/three.js","slug":"editscript-unknown-script","errorCode":null,"errorMessage":"editScript: Unknown script","messagePattern":"editScript: Unknown script","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"editor/js/Script.js","lineNumber":466,"sourceCode":"\t\t\t\t\tsource = object.material.fragmentShader || '';\n\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 'programInfo':\n\n\t\t\t\t\tmode = 'json';\n\t\t\t\t\tconst json = {\n\t\t\t\t\t\tdefines: object.material.defines,\n\t\t\t\t\t\tuniforms: object.material.uniforms,\n\t\t\t\t\t\tattributes: object.material.attributes\n\t\t\t\t\t};\n\t\t\t\t\tsource = JSON.stringify( json, null, '\\t' );\n\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\n\t\t\t\t\tthrow new Error( 'editScript: Unknown script' );\n\n\t\t\t}\n\n\t\t}\n\n\t\tsetTitle( object, script );\n\n\t\tcurrentMode = mode;\n\t\tcurrentScript = script;\n\t\tcurrentObject = object;\n\n\t\tif ( mode === 'javascript' ) loadThreeDefs();\n\n\t\tcontainer.setDisplay( '' );\n\t\tcodemirror.setValue( source );\n\t\tcodemirror.clearHistory();\n\t\tif ( mode === 'json' ) mode = { name: 'javascript', json: true };\n\t\tcodemirror.setOption( 'mode', mode );","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/editor/js/Script.js#L448-L484","documentation":"Thrown by the three.js editor's editScript signal handler when the script argument is a string that is not 'vertexShader', 'fragmentShader', or 'programInfo'. The switch assigns mode/source for each known kind and its default branch throws. Because this handler runs before it calls setTitle(object, script) at Script.js:472, this error fires first and preempts error [0] for the same bad input. The two guards exist as a pair to keep the mode-assignment switch and the title switch consistent.","triggerScenarios":"Any signals.editScript.dispatch(object, str) where str is not one of the three recognized literals. The stock editor never does this; it arises from custom dispatchers, editor plugins, or a key renamed on one side of the pair of switches.","commonSituations":"A plugin or fork that adds a new editable script type and updates the title switch but forgets the mode/source switch (or vice versa). Passing a DOM event name or a material UUID where the script key is expected. Copy-paste errors introducing an unhandled literal.","solutions":["Grep for every signals.editScript.dispatch(...) and confirm each string argument is one of 'vertexShader' | 'fragmentShader' | 'programInfo' (or that the argument is a script object).","If you intended a new kind, add a matching case to the editScript switch (Script.js:436) that sets mode and source, AND to the setTitle switch (Script.js:398).","If the dispatch is coming from Sidebar.Script.js with an object, ensure the object is not being stringified or replaced by a stray string before dispatch."],"exampleFix":"// before — unhandled literal\nswitch ( script ) {\n  case 'vertexShader': /* ... */ break;\n  // ...\n  default: throw new Error( 'editScript: Unknown script' );\n}\n\n// after — add the missing case so mode/source are assigned\nswitch ( script ) {\n  case 'vertexShader': /* ... */ break;\n  case 'geometryShader':\n    mode = 'glsl';\n    source = object.material.geometryShader || '';\n    break;\n  // ...\n  default: throw new Error( 'editScript: Unknown script' );\n}","handlingStrategy":"validation","validationCode":"const SCRIPT_KEYS = new Set( [ 'vertexShader', 'fragmentShader', 'programInfo' ] );\nfunction safeEditScript( object, script ) {\n  if ( typeof script === 'string' && ! SCRIPT_KEYS.has( script ) ) {\n    throw new TypeError( `Unsupported editScript key: ${script}` );\n  }\n  signals.editScript.dispatch( object, script );\n}","typeGuard":"function isKnownScriptKey( v ) {\n  return v === 'vertexShader' || v === 'fragmentShader' || v === 'programInfo';\n}\nfunction isEditableScript( v ) {\n  if ( v !== null && typeof v === 'object' && typeof v.source === 'string' ) return true;\n  return isKnownScriptKey( v );\n}","tryCatchPattern":"try {\n  signals.editScript.dispatch( object, script );\n} catch ( err ) {\n  if ( /editScript: Unknown script/.test( err.message ) ) {\n    console.error( 'Rejected editScript key, ignoring:', script );\n  } else throw err;\n}","preventionTips":["Grep signals.editScript.dispatch to audit every call site for the three allowed literals.","When adding a script kind, update both the mode/source switch and the title switch in the same commit.","Route programmatic edits through a single helper that validates the key."],"tags":["editor","script","shader","switch-enum"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}