windmill-labs/windmill · error

Cannot save invalid repository

Error message

Cannot save invalid repository

What it means

saveRepository persists one git-sync repository entry. It throws when the entry is absent at the given index or when validateRepository(repo, idx) fails, preventing invalid repository configurations (e.g., missing path, bad format, duplicate settings) from being written.

Source

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

	// Migration utility for legacy repositories
	function migrateLegacyRepository(repo: GitSyncRepository): GitSyncRepository {
		if (!repo.legacyImported) {
			return repo // Already migrated or not legacy
		}

		// Create migrated repository - exclude_types_override should already be applied in settings.include_type
		// from the loadSettings logic, so we just need to clear the override and mark as migrated
		return {
			...repo,
			exclude_types_override: [], // Clear the override since it's now integrated into include_type
			legacyImported: false // Mark as migrated
		}
	}

	async function saveRepository(idx: number, savedWithoutInit = false) {
		const repo = repositories[idx]
		if (!repo || !validateRepository(repo, idx)) {
			throw new Error('Cannot save invalid repository')
		}

		// Migrate legacy repository if needed
		const repoToSave = repo.legacyImported ? migrateLegacyRepository(repo) : repo

		// Use the new individual repository API instead of saving all repositories
		await WorkspaceService.editGitSyncRepository({
			workspace,
			requestBody: {
				git_repo_resource_path: `$res:${repoToSave.git_repo_resource_path}`,
				repository: {
					git_repo_resource_path: `$res:${repoToSave.git_repo_resource_path}`,
					script_path: repoToSave.script_path,
					use_individual_branch: repoToSave.use_individual_branch,
					group_by_folder: repoToSave.group_by_folder,
					settings: repoToSave.settings,
					exclude_types_override: repoToSave.exclude_types_override,
					auto_pull: repoToSave.auto_pull,

View on GitHub (pinned to e474e8803c)

Solutions

  1. Run validateRepository (or inspect its reported field errors) and fix the repo fields before saving.
  2. Verify the index is current after any add/remove operations on repositories.
  3. Surface validation errors in the form UI and disable the save button until valid.

Example fix

// before
await saveRepository(idx)
// after
const repo = repositories[idx]
if (repo && validateRepository(repo, idx)) {
  await saveRepository(idx)
} else {
  toast.error('Fix repository validation errors before saving')
}
Defensive patterns

Strategy: validation

Validate before calling

const repo = repositories[idx]
if (!repo || !validateRepository(repo, idx)) {
  toast.error('Fix repository validation errors before saving')
  return
}

Type guard

function isSavable(r: RepositoryEntry | undefined, idx: number): r is RepositoryEntry {
  return !!r && validateRepository(r, idx)
}

Try / catch

try {
  await saveRepository(idx)
} catch (e) {
  if (e.message === 'Cannot save invalid repository') {
    showValidationErrors(repositories[idx])
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling saveRepository(idx) on a repository whose validation fails — missing required fields (path, resource), invalid folder/location values, or duplicate conflicting settings — or with an out-of-range index.

Common situations: Submit triggered before form validation completed; repositories mutated so idx no longer points at the intended entry; legacy-imported repos missing newly required fields.

Related errors


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