{"record":{"id":"ffd7fa96ad8e5e50","repo":"semaphoreui/semaphore","slug":"error-at-environments-d-s","errorCode":null,"errorMessage":"error at environments[%d]: %s","messagePattern":"error at environments\\[(.+?)\\]: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project/restore.go","lineNumber":538,"sourceCode":"\t}\n\n\tworkflow.Nodes = nodes\n\t// workflow.Edges is carried by the embedded WorkflowTemplate and references\n\t// nodes by the IDs preserved above; writeWorkflowGraph remaps them.\n\n\tnewWorkflow, err := b.workflowStore.CreateWorkflowTemplate(workflow)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tb.workflows = append(b.workflows, newWorkflow)\n\treturn nil\n}\n\nfunc (backup *BackupFormat) Verify() error {\n\tfor i, o := range backup.Environments {\n\t\tif err := o.Verify(backup); err != nil {\n\t\t\treturn fmt.Errorf(\"error at environments[%d]: %s\", i, err.Error())\n\t\t}\n\t}\n\tfor i, o := range backup.Views {\n\t\tif err := o.Verify(backup); err != nil {\n\t\t\treturn fmt.Errorf(\"error at views[%d]: %s\", i, err.Error())\n\t\t}\n\t}\n\tfor i, o := range backup.Schedules {\n\t\tif err := o.Verify(backup); err != nil {\n\t\t\treturn fmt.Errorf(\"error at templates[%d]: %s\", i, err.Error())\n\t\t}\n\t}\n\tfor i, o := range backup.Keys {\n\t\tif err := o.Verify(backup); err != nil {\n\t\t\treturn fmt.Errorf(\"error at keys[%d]: %s\", i, err.Error())\n\t\t}\n\t}\n\tfor i, o := range backup.Repositories {","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/project/restore.go#L520-L556","documentation":"BackupFormat.Verify() validates every entry of the backup for referential integrity, starting with environments. This error wraps any error returned by BackupEnvironment.Verify for backup.Environments[i], prefixing it with the index so the caller knows which environment entry is invalid.","triggerScenarios":"Calling BackupFormat.Verify() on a backup where the environment at index i fails its own verification — typically its inventory, vaultKey, vaults[].vaultKey, view, or buildTemplate references do not exist in the corresponding backup sections, or names are duplicated.","commonSituations":"Programmatic backup generation that omitted referenced sections; hand-edited backup JSON with broken cross-references; backup from a different project merged in; partial backups.","solutions":["Read the wrapped inner message to identify the exact broken reference in environments[i]","Add the missing referenced entry (inventory/key/view/template) to the backup file","Fix the environment's reference to match an existing name in the corresponding section","Run Verify() on the freshly exported backup before importing to catch issues at export time"],"exampleFix":"// before\nif err := backup.Verify(); err != nil {\n    log.Print(err) // \"error at environments[2]: vault_key does not exist in keys[].name\"\n}\n// after: fix environments[2] in the backup so keys[] contains the referenced vault_key\n{\"environments\": [{\"name\": \"prod\", \"vault_key\": \"prod-key\"}], \"keys\": [{\"name\": \"prod-key\"}]}","handlingStrategy":"try-catch","validationCode":"if err := backup.Verify(); err != nil {\n    var idx int\n    if n, _ := fmt.Sscanf(err.Error(), \"error at environments[%d]\", &idx); n == 1 {\n        log.Printf(\"environment entry %d is invalid, fix it before import\", idx)\n    }\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := backup.Verify(); err != nil {\n    if strings.HasPrefix(err.Error(), \"error at environments[\") {\n        // parse index and inner message; repair backup.Environments[i] before Restore\n        return fmt.Errorf(\"invalid backup: %w\", err)\n    }\n    return err\n}","preventionTips":["Run Verify() immediately after generating or editing a backup","Fix the inner (wrapped) error, not just the index prefix","Keep all sections referenced by environments complete in the backup","Validate merged backup files for cross-references"],"tags":["go","backup","validation","environments"],"backgroundTag":"schema-validation-failed","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"}