{"record":{"id":"72348648948fe75c","repo":"hashicorp/packer","slug":"failed-to-add-artifact-for-q-s","errorCode":null,"errorMessage":"failed to add artifact for %q: %s","messagePattern":"failed to add artifact for %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":792,"sourceCode":"\t\t\t\t\"failed to create decoder for HCP Packer artifact: %w\",\n\t\t\t\terr)\n\t\t}\n\n\t\tstate := art.State(packerSDKRegistry.ArtifactStateURI)\n\t\tif state == nil {\n\t\t\tlog.Printf(\"[WARN] - artifact %q returned a nil value for the HCP state, ignoring\", art.BuilderId())\n\t\t\tcontinue\n\t\t}\n\n\t\terr = decoder.Decode(state)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"[WARN] - artifact %q failed to be decoded to an HCP artifact, this is probably because it is not compatible: %s\", art.BuilderId(), err)\n\t\t\tcontinue\n\t\t}\n\n\t\terr = bucket.UpdateArtifactForBuild(buildName, sdkImages...)\n\t\tif err != nil {\n\t\t\treturn packerSDKArtifacts, fmt.Errorf(\"failed to add artifact for %q: %s\", buildName, err)\n\t\t}\n\t}\n\n\tbuild, err := bucket.Version.Build(buildName)\n\tif err != nil {\n\t\treturn packerSDKArtifacts, fmt.Errorf(\n\t\t\t\"failed to get build %q from version being built. This is a Packer bug.\",\n\t\t\tbuildName)\n\t}\n\tif len(build.Artifacts) == 0 {\n\t\treturn packerSDKArtifacts, &NotAHCPArtifactError{\n\t\t\tfmt.Errorf(\"No HCP Packer-compatible artifacts were found for the build\"),\n\t\t}\n\t}\n\n\tfor _, sbom := range build.CompressedSboms {\n\t\terr = bucket.uploadSbom(ctx, buildName, sbom)\n\t\tif err != nil {","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L774-L810","documentation":"After successfully decoding an artifact's HCP images, doCompleteBuild uploads them via bucket.UpdateArtifactForBuild. If that HCP Packer API call fails, the completed-build flow aborts with this error naming the build, and the build is subsequently marked FAILED even though the local build itself succeeded.","triggerScenarios":"Bucket.CompleteBuild -> doCompleteBuild -> bucket.UpdateArtifactForBuild(buildName, sdkImages...) returns an error: network failure, authentication expiry, API 4xx/5xx, or invalid image payload rejected by the registry.","commonSituations":"HCP token expiring during a long build; transient network outage between build end and artifact upload; image metadata exceeding API limits; HCP Packer service incident; proxy intercepting the upload request.","solutions":["Re-run the build (or resume) ensuring stable connectivity to api.cloud.hashicorp.com","Refresh HCP credentials or shorten build duration so tokens don't expire mid-run","Check the wrapped inner error for the HTTP/gRPC status and address it (401 -> re-auth, 429 -> backoff, 5xx -> retry later)","Verify the builder's artifact state (registry_image IDs) is valid and not oversized"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: verify token validity and reachability before long builds\n// curl -sS -o /dev/null -w '%{http_code}' -H \"Authorization: Bearer $HCP_TOKEN\" https://api.cloud.hashicorp.com/\n// Token refresh: ensure HCP_CLIENT_ID/HCP_CLIENT_SECRET are set so Packer can renew tokens","typeGuard":null,"tryCatchPattern":"// Go\nif err := bucket.CompleteBuild(ctx, buildName, arts, ui, nil); err != nil {\n\tif strings.Contains(err.Error(), \"failed to add artifact for\") {\n\t\t// upload failed (auth/network/429/5xx): retry with backoff\n\t\treturn retryWithBackoff(ctx, 3, func() error {\n\t\t\t_, e := bucket.CompleteBuild(ctx, buildName, arts, ui, nil)\n\t\t\treturn e\n\t\t})\n\t}\n\treturn err\n}","preventionTips":["Ensure HCP credentials support mid-run token renewal (set client id/secret, not just a static token)","Add CI retry-on-failure for the artifact upload phase","Check the inner error's HTTP status: 401 -> re-auth, 429 -> back off, 5xx -> retry later","Avoid over-sized image payloads; keep artifact state within API limits"],"tags":["hcp-packer","artifact-upload","api-call"],"backgroundTag":"artifact-upload-failed","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"}