windmill-labs/windmill · error · Error

Module not found or is not a rawscript

Error message

Module not found or is not a rawscript

What it means

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.

Source

Thrown at frontend/src/lib/components/copilot/chat/flow/FlowAIChat.svelte:101

						)
					}
				}
			}
		},

		// ai chat tools
		setCode: async (id: string, code: string) => {
			// 1. Take snapshot only if none exists (preserves baseline for cumulative changes)
			if (!diffManager?.beforeFlow) {
				const snapshot = $state.snapshot(flowStore).val
				diffManager?.setBeforeFlow(snapshot)
				diffManager?.setEditMode(true)
			}

			// 2. Apply the code change
			const module = updateRawScriptModuleContent(flowStore.val, id, code)
			if (!module) {
				throw new Error('Module not found or is not a rawscript')
			}

			inlineScriptSession.set(id, code)
			const { input_transforms, schema } = await loadSchemaFromModule(module, opWorkspace?.())
			module.value.input_transforms = input_transforms
			refreshStateStore(flowStore)

			// Update exprsToSet if this module is currently selected
			if (id === selectedId && exprsToSet) {
				exprsToSet.set(input_transforms)
			}

			if (flowStateStore.val[id]) {
				flowStateStore.val[id].schema = schema
			} else {
				flowStateStore.val[id] = {
					schema
				}

View on GitHub (pinned to e474e8803c)

Solutions

  1. Confirm the module id in the tool call matches an existing rawscript module in the current flow
  2. Re-sync/reload the flow store so flowStore.val reflects the current flow before applying
  3. Handle the null return gracefully (toast and abort the apply) instead of letting it throw

Example fix

// before
const module = updateRawScriptModuleContent(flowStore.val, id, code)
if (!module) throw new Error('Module not found or is not a rawscript')
// after
const module = updateRawScriptModuleContent(flowStore.val, id, code)
if (!module) {
  sendUserToast(`Module ${id} not found or not a rawscript; refresh the flow and retry`, true)
  return null
}
Defensive patterns

Strategy: validation

Validate before calling

const target = flowStore.val.modules.find((m) => m.id === id)
if (!target || target.type !== 'rawscript') { sendUserToast('Target module missing or not a rawscript', true); return }

Type guard

function isRawscriptModule(m: any): boolean { return !!m && m.type === 'rawscript' }

Try / catch

try { applyCodeChange(id, code) } catch (e) { sendUserToast(e.message, true); refreshStateStore(flowStore) }

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/1232a4e6b7c645a9. Report an issue: GitHub.