{"record":{"id":"6ae193154dba536f","repo":"semaphoreui/semaphore","slug":"inventory-does-not-exist-in-inventories-name","errorCode":null,"errorMessage":"inventory does not exist in inventories[].name","messagePattern":"inventory does not exist in inventories\\[\\]\\.name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project/restore.go","lineNumber":253,"sourceCode":"\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}\n\t}\n\n\tif e.View != nil && getEntryByName[BackupView](e.View, backup.Views) == nil {\n\t\treturn fmt.Errorf(\"view does not exist in views[].name\")","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/project/restore.go#L235-L271","documentation":"Thrown by BackupTemplate.Verify when the template has an optional Inventory set but its name is absent from backup.Inventories. Because the reference is optional (nil skipped), the error only fires for templates that actually declare an inventory that cannot be resolved.","triggerScenarios":"Verify with e.Inventory != nil and getEntryByName[BackupInventory](e.Inventory, backup.Inventories) == nil — inventory renamed after the backup, or inventories excluded from export while templates were included.","commonSituations":"Selective export omitting inventories; environment-specific inventories that exist in the source but not the target project; case mismatches after manual JSON editing.","solutions":["Add the inventory with that name to backup.Inventories.","Point the template's inventory field at an existing inventories[].name.","Clear the inventory reference (set to null) if the template no longer needs one."],"exampleFix":"// before\n\"templates\": [{\"name\": \"build\", \"inventory\": \"prod-inv\"}], \"inventories\": []\n// after\n\"templates\": [{\"name\": \"build\", \"inventory\": \"prod-inv\"}], \"inventories\": [{\"name\": \"prod-inv\"}]","handlingStrategy":"validation","validationCode":"if t.Inventory != nil && !invNameExists(*t.Inventory, backup.Inventories) {\n  return fmt.Errorf(\"template %q references missing inventory %q\", t.Name, *t.Inventory)\n}","typeGuard":"func invNameExists(name string, invs []BackupInventory) bool {\n  for _, i := range invs {\n    if i.Name == name { return true }\n  }\n  return false\n}","tryCatchPattern":"if err := tmpl.Verify(backup); err != nil {\n  if strings.Contains(err.Error(), \"inventory does not exist\") {\n    // add the inventory or clear the reference\n  }\n}","preventionTips":["Include all inventories referenced by templates in every export.","Check name spelling/casing against inventories[].name before restoring.","Null out optional references when the target entity was intentionally deleted."],"tags":["restore","backup","referential-integrity","inventory","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"}