{"record":{"id":"826ad90f9a726e4f","repo":"hashicorp/packer","slug":"addlabelstobuild-w","errorCode":null,"errorMessage":"AddLabelsToBuild: %w","messagePattern":"AddLabelsToBuild: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.version.go","lineNumber":115,"sourceCode":"\tbuild, err := version.Build(buildName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"AddArtifactToBuild: %w\", err)\n\t}\n\n\terr = build.AddArtifacts(artifacts...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"AddArtifactToBuild: %w\", err)\n\t}\n\n\tversion.StoreBuild(buildName, build)\n\treturn nil\n}\n\n// AddLabelsToBuild merges the contents of data to the labels associated with the build referred to by buildName.\nfunc (version *Version) AddLabelsToBuild(buildName string, data map[string]string) error {\n\tbuild, err := version.Build(buildName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"AddLabelsToBuild: %w\", err)\n\t}\n\n\tbuild.MergeLabels(data)\n\n\tversion.StoreBuild(buildName, build)\n\treturn nil\n}\n\n// AddSHAToBuildLabels adds the Git SHA for the current version (if set) as a label for all the builds of the version\nfunc (version *Version) AddSHAToBuildLabels(sha string) {\n\tversion.builds.Range(func(_, v any) bool {\n\t\tb, ok := v.(*Build)\n\t\tif !ok {\n\t\t\treturn true\n\t\t}\n\n\t\tb.MergeLabels(map[string]string{\n\t\t\t\"git_sha\": sha,","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.version.go#L97-L133","documentation":"Wraps a failure from Version.Build while resolving the named build, inside AddLabelsToBuild. It means labels could not be attached because no build with that name exists in the version (or the stored entry is not a valid Build).","triggerScenarios":"AddLabelsToBuild is called (via UpdateLabelsForBuild) with a buildName absent from version.builds — e.g. label updates arriving for a component this Packer run never created a build for.","commonSituations":"Same split-brain scenario as AddArtifactToBuild: parallel builds sharing a bucket, component name mismatches, or label updates landing after the version instance was replaced.","solutions":["Verify the build/component name matches one created during this run","Run one Packer invocation per bucket/version to keep registry state coherent","Check that labels are being published to the correct bucket and fingerprint","Inspect the wrapped error to distinguish 'no associated build found' from an invalid Build type"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Ensure the build exists before merging labels\nif !version.HasBuild(buildName) {\n    return fmt.Errorf(\"cannot add labels: build %q not found on version\", buildName)\n}","typeGuard":"if _, err := version.Build(name); err != nil {\n    return fmt.Errorf(\"labels target build %q unavailable: %w\", name, err)\n}","tryCatchPattern":"if err := version.AddLabelsToBuild(name, labels); err != nil {\n    if strings.Contains(err.Error(), \"no associated build found\") {\n        // create the build first, then re-apply labels\n    }\n}","preventionTips":["Apply labels only to builds created within the same run","Verify component names against the template's builder names","Avoid sharing one bucket across concurrent Packer invocations"],"tags":["hcp-packer","labels","build-lookup"],"backgroundTag":"build-not-found","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}