{"record":{"id":"7373c3d308d2343d","repo":"semaphoreui/semaphore","slug":"repository-does-not-exist-in-repositories-name","errorCode":null,"errorMessage":"repository does not exist in repositories[].name","messagePattern":"repository does not exist in repositories\\[\\]\\.name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project/restore.go","lineNumber":249,"sourceCode":"\trepo := e.Repository\n\trepo.ProjectID = b.meta.ID\n\trepo.SSHKeyID = SSHKeyID\n\n\tnewRepo, err := b.store.CreateRepository(repo)\n\tif err != nil {\n\t\treturn err\n\t}\n\tb.repositories = append(b.repositories, newRepo)\n\treturn nil\n}\n\nfunc (e BackupTemplate) Verify(backup *BackupFormat) error {\n\tif err := verifyDuplicate[BackupTemplate](e.Name, backup.Templates); err != nil {\n\t\treturn err\n\t}\n\n\tif getEntryByName[BackupRepository](&e.Repository, backup.Repositories) == nil {\n\t\treturn fmt.Errorf(\"repository does not exist in repositories[].name\")\n\t}\n\n\tif e.Inventory != nil && getEntryByName[BackupInventory](e.Inventory, backup.Inventories) == nil {\n\t\treturn fmt.Errorf(\"inventory does not exist in inventories[].name\")\n\t}\n\n\tif e.VaultKey != nil && getEntryByName[BackupAccessKey](e.VaultKey, backup.Keys) == nil {\n\t\treturn fmt.Errorf(\"vault_key does not exist in keys[].name\")\n\t}\n\n\tif e.Vaults != nil {\n\t\tfor _, vault := range e.Vaults {\n\t\t\tif vault.VaultKey != nil {\n\t\t\t\tif getEntryByName[BackupAccessKey](vault.VaultKey, backup.Keys) == nil {\n\t\t\t\t\treturn fmt.Errorf(\"vaults[].vaultKey does not exist in keys[].name\")\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/project/restore.go#L231-L267","documentation":"Thrown by BackupTemplate.Verify when the template's inline repository reference (e.Repository) is not found by name in backup.Repositories. Templates reference a repository by name, and this check guarantees the referenced repository exists before restore proceeds.","triggerScenarios":"Verify on a BackupFormat whose templates[] entry points at a repositories[] name that does not exist — repository omitted from the export, renamed, or typo in the template's repository field.","commonSituations":"Migrating a single template without its repository; renaming a repository after backup; hand-merging backups from two projects; export filters that dropped repositories but kept templates.","solutions":["Add the missing repository to backup.Repositories with the exact name the template references.","Update the template's repository field to an existing repositories[].name.","Delete the template from the backup if it is no longer needed."],"exampleFix":"// before\n\"templates\": [{\"name\": \"build\", \"repository\": \"app-repo\"}], \"repositories\": []\n// after\n\"templates\": [{\"name\": \"build\", \"repository\": \"app-repo\"}], \"repositories\": [{\"name\": \"app-repo\"}]","handlingStrategy":"validation","validationCode":"for _, t := range backup.Templates {\n  if !repoNameExists(t.Repository.Name, backup.Repositories) {\n    return fmt.Errorf(\"template %q references missing repository %q\", t.Name, t.Repository.Name)\n  }\n}","typeGuard":"func repoNameExists(name string, repos []BackupRepository) bool {\n  for _, r := range repos {\n    if r.Name == name { return true }\n  }\n  return false\n}","tryCatchPattern":"if err := tmpl.Verify(backup); err != nil {\n  if strings.Contains(err.Error(), \"repository does not exist\") {\n    // add the repository or fix the reference, then retry\n  }\n}","preventionTips":["Export templates and their repositories in the same backup scope.","Run whole-backup Verify before restore.","Keep repository names stable across backup/restore cycles."],"tags":["restore","backup","referential-integrity","template","go"],"backgroundTag":"entity-not-found","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}