{"record":{"id":"118acd6485b8305c","repo":"hashicorp/packer","slug":"addartifacttobuild-w","errorCode":null,"errorMessage":"AddArtifactToBuild: %w","messagePattern":"AddArtifactToBuild: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.version.go","lineNumber":99,"sourceCode":"\tif !ok {\n\t\treturn nil, fmt.Errorf(\"the build for the component %q does not appear to be a valid registry Build\", buildName)\n\t}\n\n\treturn b, nil\n}\n\n// HasBuild checks if version has a stored build associated with buildName.\nfunc (version *Version) HasBuild(buildName string) bool {\n\t_, ok := version.builds.Load(buildName)\n\n\treturn ok\n}\n\n// AddArtifactToBuild appends one or more artifacts to the build referred to by buildName.\nfunc (version *Version) AddArtifactToBuild(buildName string, artifacts ...packerSDKRegistry.Image) error {\n\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","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.version.go#L81-L117","documentation":"Wraps a failure from Version.Build while resolving the named build, inside AddArtifactToBuild. It means the build referenced by buildName could not be found (no associated build for that name) or was not a valid registry Build, so the artifact could not be attached.","triggerScenarios":"AddArtifactToBuild is called (via UpdateArtifactForBuild) with a buildName that has no entry in version.builds — e.g. artifacts arriving for a component whose build was never created for this version/fingerprint.","commonSituations":"Multiple Packer builds running against the same bucket where one finishes and publishes artifacts for a component name that another run's version instance does not know; component name mismatches between builder and registry state.","solutions":["Ensure the build was initialized for this version before publishing artifacts (check the component name matches the builder's name)","Run a single Packer invocation per bucket/version to avoid split-brain registry state","Check for typos in build/component names in the template","Read the wrapped error: 'no associated build found for the name X' vs invalid Build type to pick the right fix"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Before publishing artifacts, confirm the build exists on this version\nif !version.HasBuild(buildName) {\n    return fmt.Errorf(\"build %q not initialized for this version\", buildName)\n}","typeGuard":"if b, err := version.Build(name); err != nil || b == nil {\n    // build missing: initialize before AddArtifactToBuild\n}","tryCatchPattern":"if err := version.AddArtifactToBuild(name, imgs...); err != nil {\n    if strings.Contains(err.Error(), \"no associated build found\") {\n        // initialize the build for this version first, then retry\n    }\n}","preventionTips":["Initialize every component's build before publishing artifacts/labels","Match builder component names exactly with registry build names","Run one Packer invocation per bucket/version"],"tags":["hcp-packer","build-lookup","registry"],"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"}