windmill-labs/windmill · error

Cannot load drafts of kind ${itemKind}

Error message

Cannot load drafts of kind ${itemKind}

What it means

editRouteFor maps a draft item kind (script, flow, app, raw_app) to its editor route. When OtherUserDraftLoad is asked to stage a draft of a kind that has no known editor route, it throws. It is a guard against viewing drafts of unsupported item types.

Source

Thrown at frontend/src/lib/components/otherUserDraftLoad.svelte.ts:66

// One-shot handoff: set by the Load action, consumed by the editor's loader.
const pending = new SvelteMap<string, PendingOtherUserDraftLoad>()
// Live overlay sessions, keyed by (workspace, itemKind, path).
const active = new SvelteMap<string, ActiveSession>()
// Keys whose overwrite-confirmation modal is currently open.
const overwriteOpen = new SvelteSet<string>()

export function editRouteFor(itemKind: UserDraftItemKind, path: string): string {
	switch (itemKind) {
		case 'script':
			return `${base}/scripts/edit/${path}`
		case 'flow':
			return `${base}/flows/edit/${path}`
		case 'app':
			return `${base}/apps/edit/${path}`
		case 'raw_app':
			return `${base}/apps_raw/edit/${path}`
		default:
			throw new Error(`Cannot load drafts of kind ${itemKind}`)
	}
}

export const OtherUserDraftLoad = {
	/**
	 * Stage a load. The editor's loader picks it up via `takePending`. When
	 * `navigate`, route to the item's edit page (home-page entry point); the
	 * in-editor entry point reloads in place instead.
	 */
	stage(
		workspace: string,
		itemKind: UserDraftItemKind,
		value: unknown,
		path: string,
		ownerLabel: string,
		opts: { navigate: boolean }
	): void {
		pending.set(keyOf(workspace, itemKind, path), { workspace, itemKind, path, value, ownerLabel })

View on GitHub (pinned to e474e8803c)

Solutions

  1. Extend the switch in editRouteFor with a case returning the editor route for the new kind
  2. Check the draft record's kind field — fix stale data or the producer writing the wrong kind
  3. If the kind should not be draftable, filter it out before calling stage

Example fix

// before
case 'raw_app':
  return `${base}/apps_raw/edit/${path}`
default:
  throw new Error(`Cannot load drafts of kind ${itemKind}`)
// after
case 'raw_app':
  return `${base}/apps_raw/edit/${path}`
case 'resource':
  return `${base}/resources/edit/${path}`
default:
  throw new Error(`Cannot load drafts of kind ${itemKind}`)
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['script','flow','app','raw_app']
if (!SUPPORTED.includes(itemKind)) return null // skip staging instead of throwing

Type guard

function isDraftableKind(k: string): k is 'script'|'flow'|'app'|'raw_app' {
  return ['script','flow','app','raw_app'].includes(k)
}

Try / catch

try { route = editRouteFor(kind) } catch { route = null; showUnsupportedNotice(kind) }

Prevention

When it happens

Trigger: Calling OtherUserDraftLoad.stage (which calls editRouteFor) with itemKind set to anything other than 'script', 'flow', 'app', or 'raw_app' — e.g. a new resource/kind added elsewhere but not wired into this switch.

Common situations: Loading another user's draft of a newly added item kind before this switch was extended; a stale or malformed draft record whose kind field was corrupted or renamed.

Related errors


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