{"record":{"id":"1232a4e6b7c645a9","repo":"windmill-labs/windmill","slug":"module-not-found-or-is-not-a-rawscript","errorCode":null,"errorMessage":"Module not found or is not a rawscript","messagePattern":"Module not found or is not a rawscript","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/flow/FlowAIChat.svelte","lineNumber":101,"sourceCode":"\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// ai chat tools\n\t\tsetCode: async (id: string, code: string) => {\n\t\t\t// 1. Take snapshot only if none exists (preserves baseline for cumulative changes)\n\t\t\tif (!diffManager?.beforeFlow) {\n\t\t\t\tconst snapshot = $state.snapshot(flowStore).val\n\t\t\t\tdiffManager?.setBeforeFlow(snapshot)\n\t\t\t\tdiffManager?.setEditMode(true)\n\t\t\t}\n\n\t\t\t// 2. Apply the code change\n\t\t\tconst module = updateRawScriptModuleContent(flowStore.val, id, code)\n\t\t\tif (!module) {\n\t\t\t\tthrow new Error('Module not found or is not a rawscript')\n\t\t\t}\n\n\t\t\tinlineScriptSession.set(id, code)\n\t\t\tconst { input_transforms, schema } = await loadSchemaFromModule(module, opWorkspace?.())\n\t\t\tmodule.value.input_transforms = input_transforms\n\t\t\trefreshStateStore(flowStore)\n\n\t\t\t// Update exprsToSet if this module is currently selected\n\t\t\tif (id === selectedId && exprsToSet) {\n\t\t\t\texprsToSet.set(input_transforms)\n\t\t\t}\n\n\t\t\tif (flowStateStore.val[id]) {\n\t\t\t\tflowStateStore.val[id].schema = schema\n\t\t\t} else {\n\t\t\t\tflowStateStore.val[id] = {\n\t\t\t\t\tschema\n\t\t\t\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/flow/FlowAIChat.svelte#L83-L119","documentation":"In FlowAIChat.svelte, applying an AI code change looks up the target module with updateRawScriptModuleContent(flowStore.val, id, code). If the flow store contains no module with that id, or the module exists but is not a rawscript, the lookup returns null and this error is thrown before the schema is loaded.","triggerScenarios":"The AI chat references a module id that no longer exists in flowStore.val (module deleted, flow switched, stale id from a previous step), or the id points to a non-rawscript module (e.g. a regular script or code step) while the tool assumed rawscript.","commonSituations":"User edited the flow between the AI plan and the apply step; the chat session targets a different flow version; the tool picked the wrong module kind for a step created as 'script' rather than 'rawscript'.","solutions":["Confirm the module id in the tool call matches an existing rawscript module in the current flow","Re-sync/reload the flow store so flowStore.val reflects the current flow before applying","Handle the null return gracefully (toast and abort the apply) instead of letting it throw"],"exampleFix":"// before\nconst module = updateRawScriptModuleContent(flowStore.val, id, code)\nif (!module) throw new Error('Module not found or is not a rawscript')\n// after\nconst module = updateRawScriptModuleContent(flowStore.val, id, code)\nif (!module) {\n  sendUserToast(`Module ${id} not found or not a rawscript; refresh the flow and retry`, true)\n  return null\n}","handlingStrategy":"validation","validationCode":"const target = flowStore.val.modules.find((m) => m.id === id)\nif (!target || target.type !== 'rawscript') { sendUserToast('Target module missing or not a rawscript', true); return }","typeGuard":"function isRawscriptModule(m: any): boolean { return !!m && m.type === 'rawscript' }","tryCatchPattern":"try { applyCodeChange(id, code) } catch (e) { sendUserToast(e.message, true); refreshStateStore(flowStore) }","preventionTips":["Re-read the flow store immediately before applying AI edits","Abort pending AI applies when the flow changes underneath","Match tool operations to the module type (script vs rawscript)"],"tags":["svelte","flow-editor","lookup-failed"],"backgroundTag":"module-not-found","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}