{"record":{"id":"4e27d973ac504460","repo":"windmill-labs/windmill","slug":"cannot-save-invalid-repository","errorCode":null,"errorMessage":"Cannot save invalid repository","messagePattern":"Cannot save invalid repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts","lineNumber":512,"sourceCode":"\t// Migration utility for legacy repositories\n\tfunction migrateLegacyRepository(repo: GitSyncRepository): GitSyncRepository {\n\t\tif (!repo.legacyImported) {\n\t\t\treturn repo // Already migrated or not legacy\n\t\t}\n\n\t\t// Create migrated repository - exclude_types_override should already be applied in settings.include_type\n\t\t// from the loadSettings logic, so we just need to clear the override and mark as migrated\n\t\treturn {\n\t\t\t...repo,\n\t\t\texclude_types_override: [], // Clear the override since it's now integrated into include_type\n\t\t\tlegacyImported: false // Mark as migrated\n\t\t}\n\t}\n\n\tasync function saveRepository(idx: number, savedWithoutInit = false) {\n\t\tconst repo = repositories[idx]\n\t\tif (!repo || !validateRepository(repo, idx)) {\n\t\t\tthrow new Error('Cannot save invalid repository')\n\t\t}\n\n\t\t// Migrate legacy repository if needed\n\t\tconst repoToSave = repo.legacyImported ? migrateLegacyRepository(repo) : repo\n\n\t\t// Use the new individual repository API instead of saving all repositories\n\t\tawait WorkspaceService.editGitSyncRepository({\n\t\t\tworkspace,\n\t\t\trequestBody: {\n\t\t\t\tgit_repo_resource_path: `$res:${repoToSave.git_repo_resource_path}`,\n\t\t\t\trepository: {\n\t\t\t\t\tgit_repo_resource_path: `$res:${repoToSave.git_repo_resource_path}`,\n\t\t\t\t\tscript_path: repoToSave.script_path,\n\t\t\t\t\tuse_individual_branch: repoToSave.use_individual_branch,\n\t\t\t\t\tgroup_by_folder: repoToSave.group_by_folder,\n\t\t\t\t\tsettings: repoToSave.settings,\n\t\t\t\t\texclude_types_override: repoToSave.exclude_types_override,\n\t\t\t\t\tauto_pull: repoToSave.auto_pull,","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts#L494-L530","documentation":"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.","triggerScenarios":"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.","commonSituations":"Submit triggered before form validation completed; repositories mutated so idx no longer points at the intended entry; legacy-imported repos missing newly required fields.","solutions":["Run validateRepository (or inspect its reported field errors) and fix the repo fields before saving.","Verify the index is current after any add/remove operations on repositories.","Surface validation errors in the form UI and disable the save button until valid."],"exampleFix":"// before\nawait saveRepository(idx)\n// after\nconst repo = repositories[idx]\nif (repo && validateRepository(repo, idx)) {\n  await saveRepository(idx)\n} else {\n  toast.error('Fix repository validation errors before saving')\n}","handlingStrategy":"validation","validationCode":"const repo = repositories[idx]\nif (!repo || !validateRepository(repo, idx)) {\n  toast.error('Fix repository validation errors before saving')\n  return\n}","typeGuard":"function isSavable(r: RepositoryEntry | undefined, idx: number): r is RepositoryEntry {\n  return !!r && validateRepository(r, idx)\n}","tryCatchPattern":"try {\n  await saveRepository(idx)\n} catch (e) {\n  if (e.message === 'Cannot save invalid repository') {\n    showValidationErrors(repositories[idx])\n    return\n  }\n  throw e\n}","preventionTips":["Gate the save button on validateRepository passing.","Re-check indexes after add/remove mutations of the repositories list.","Migrate legacy repos (migrateLegacyRepository) before validating saved data."],"tags":["svelte","git-sync","validation"],"backgroundTag":"validation-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}