windmill-labs/windmill · error

Git sync context not found. Make sure to call setGitSyncCont

Error message

Git sync context not found. Make sure to call setGitSyncContext first.

What it means

getGitSyncContext retrieves the git-sync context set via Svelte's context API under GIT_SYNC_CONTEXT_KEY. If no ancestor component called setGitSyncContext, getContext returns undefined and this throws, since every consumer assumes the provider exists.

Source

Thrown at frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts:870

		getSecondaryPromotionRepositories,

		// Helper methods
		getTargetBranch
	}
}

export type GitSyncContextType = ReturnType<typeof createGitSyncContext>

export function setGitSyncContext(workspace: string): GitSyncContextType {
	const context = createGitSyncContext(workspace)
	setContext(GIT_SYNC_CONTEXT_KEY, context)
	return context
}

export function getGitSyncContext(): GitSyncContextType {
	const context = getContext<GitSyncContextType>(GIT_SYNC_CONTEXT_KEY)
	if (!context) {
		throw new Error('Git sync context not found. Make sure to call setGitSyncContext first.')
	}
	return context
}

View on GitHub (pinned to e474e8803c)

Solutions

  1. Render the consuming component inside the component tree that calls setGitSyncContext.
  2. In tests/previews, wrap the component in a harness that calls setGitSyncContext with a stub context.
  3. If the component must work standalone, accept an optional props-based fallback instead of relying on context.

Example fix

// before (test)
render(GitSyncPanel)
// after
render({
  Component: GitSyncPanel,
  context: setGitSyncContext(createStubGitSyncContext())
})
Defensive patterns

Strategy: try-catch

Type guard

function hasGitSyncContext(): boolean {
  return getContext<GitSyncContextType | undefined>(GIT_SYNC_CONTEXT_KEY) !== undefined
}

Try / catch

let ctx: GitSyncContextType
try {
  ctx = getGitSyncContext()
} catch {
  ctx = createDefaultGitSyncContext() // or render a provider-required notice
}

Prevention

When it happens

Trigger: Calling getGitSyncContext() inside a component that is not rendered beneath the component that runs setGitSyncContext (e.g., a git-sync panel mounted outside the git sync page layout, or used in a test/preview harness without the provider).

Common situations: Component moved to another route/layout without its provider wrapper; using a git-sync child component in isolation (Storybook/test) without mounting the provider; conditional rendering that skips the provider while still rendering consumers.

Related errors


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