{"record":{"id":"8352a6dac7031029","repo":"hashicorp/packer","slug":"failed-to-get-build-q-from-version-being-built-t","errorCode":null,"errorMessage":"failed to get build %q from version being built. This is a Packer bug.","messagePattern":"failed to get build %q from version being built\\. This is a Packer bug\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":798,"sourceCode":"\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 {\n\t\t\treturn packerSDKArtifacts, fmt.Errorf(\"Failed to upload sboms %s\", err)\n\t\t}\n\t}\n\n\tparErr := bucket.markBuildComplete(ctx, buildName)\n\tif parErr != nil {","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L780-L816","documentation":"After uploading artifacts, doCompleteBuild looks up the build in the locally tracked Version via bucket.Version.Build(buildName) to finalize it. If the lookup fails, the build was never stored in the version's build map during populateVersion/startBuild — an internal invariant violation, so Packer labels it a Packer bug rather than a user error.","triggerScenarios":"Bucket.CompleteBuild -> doCompleteBuild reaches bucket.Version.Build(buildName) and receives an error, meaning the build name was never registered via StoreBuild during Initialize/PopulateVersion or was registered under a different component type.","commonSituations":"Custom tooling or tests driving the registry Bucket API out of order (calling CompleteBuild without Initialize/StartBuild); component-type name mismatches between the template and the registry; genuine Packer bugs in build tracking.","solutions":["Report to hashicorp/packer with full log output — the message explicitly indicates a Packer bug","Ensure the normal flow is used: Initialize -> StartBuild -> CompleteBuild with the same bucket instance and build name","Verify the build's component type in the template matches what was registered in HCP Packer","If driving the API programmatically, call populateVersion/StoreBuild for the build before completing it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only call CompleteBuild for builds that went through Initialize/StartBuild\n// if !bucket.IsExpectingBuildForComponent(buildName) {\n//     return fmt.Errorf(\"build %q was never registered; call Initialize first\", buildName)\n// }","typeGuard":"// Go: verify the build exists in the tracked version before completing\nif _, err := bucket.Version.Build(buildName); err != nil {\n\treturn fmt.Errorf(\"build %q not tracked; initialize the bucket first\", buildName)\n}","tryCatchPattern":"// Go\n_, err := bucket.CompleteBuild(ctx, buildName, arts, ui, nil)\nif err != nil && strings.Contains(err.Error(), \"This is a Packer bug\") {\n\t// internal invariant broken: report upstream with full logs\n\treturn fmt.Errorf(\"packer internal error, please report: %w\", err)\n}","preventionTips":["Use the standard flow: Initialize -> StartBuild -> CompleteBuild on the same Bucket instance","Never call CompleteBuild for builds skipped or already done in this run","Ensure template component names match the registered build component types exactly","Report occurrences to hashicorp/packer — the message indicates a tracking bug"],"tags":["hcp-packer","internal-bug","build-lookup"],"backgroundTag":"missing-build-in-version","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"}