{"record":{"id":"92f9ba9d9f53cb17","repo":"hashicorp/packer","slug":"unable-to-load-existing-build-for-q-v","errorCode":null,"errorMessage":"Unable to load existing build for %q: %v","messagePattern":"Unable to load existing build for %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":538,"sourceCode":"// All build details will be created (if they don't exist) and added to b.Version.builds for tracking during runtime.\nfunc (bucket *Bucket) populateVersion(ctx context.Context) error {\n\t// list all this version's builds so we can figure out which ones\n\t// we want to run against. TODO: pagination?\n\texistingBuilds, err := bucket.client.ListBuilds(ctx, bucket.Name, bucket.Version.Fingerprint)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error listing builds for this existing version: %s\", err)\n\t}\n\n\tvar toCreate []string\n\tfor _, expected := range bucket.Version.expectedBuilds {\n\t\tvar found bool\n\t\tfor _, existing := range existingBuilds {\n\n\t\t\tif existing.ComponentType == expected {\n\t\t\t\tfound = true\n\t\t\t\tbuild, err := NewBuildFromCloudPackerBuild(existing)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"Unable to load existing build for %q: %v\", existing.ComponentType, err)\n\t\t\t\t}\n\n\t\t\t\t// When running against an existing build the Packer RunUUID is most likely different.\n\t\t\t\t// We capture that difference here to know that the artifacts were created in a different Packer run.\n\t\t\t\tbuild.RunUUID = bucket.Version.RunUUID\n\n\t\t\t\t// When bucket build labels represent some dynamic data set, possibly set via some user variable,\n\t\t\t\t//  we need to make sure that any newly executed builds get the labels at runtime.\n\t\t\t\tif build.IsNotDone() && len(bucket.BuildLabels) > 0 {\n\t\t\t\t\tbuild.MergeLabels(bucket.BuildLabels)\n\t\t\t\t}\n\n\t\t\t\tlog.Printf(\n\t\t\t\t\t\"[TRACE] a build of component type %s already exists; skipping the create call\", expected,\n\t\t\t\t)\n\t\t\t\tbucket.Version.StoreBuild(existing.ComponentType, build)\n\n\t\t\t\tbreak","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L520-L556","documentation":"When an existing HCP Packer build record matches one of the expected component types, populateVersion converts the cloud build object into a local Build via NewBuildFromCloudPackerBuild. If that conversion fails (malformed or missing fields in the API response, e.g. nil IDs or invalid component data), the run aborts with this message naming the component type.","triggerScenarios":"During Initialize/PopulateVersion, an existingBuild from ListBuilds has ComponentType equal to an expected build name, but NewBuildFromCloudPackerBuild(existing) returns an error — typically because the cloud build payload lacks required fields (e.g. empty ID or misformed data).","commonSituations":"HCP Packer registry entries created/modified by older Packer versions or manually, leaving builds with missing fields; corrupted build records from interrupted API updates; version changes in the HCP API schema.","solutions":["Inspect the build record for the named component in the HCP Packer portal and re-create/repair it if fields are missing","Delete the offending build (or version) in HCP Packer so Packer re-creates it on the next run","Upgrade Packer — older clients may have written records the current parser cannot read; re-run the affected build"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Inspect existing builds before initializing and skip malformed records\n// builds, err := client.ListBuilds(ctx, bucketName, fingerprint)\n// for _, b := range builds {\n//     if b.ID == nil || b.ID.IsZero() || b.ComponentType == \"\" {\n//         // repair or delete this build record in HCP before running\n//     }\n// }","typeGuard":"// Go: validate the cloud build before conversion\nfunc usableCloudBuild(b *hcpPackerModels.HashicorpCloudPacker20230101Build) bool {\n\treturn b != nil && b.ID != nil && !b.ID.IsZero() && b.ComponentType != \"\"\n}","tryCatchPattern":"// Go\nif err := bucket.Initialize(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"Unable to load existing build\") {\n\t\t// corrupted build record: delete the build/version in HCP and re-run\n\t\treturn fmt.Errorf(\"repair the HCP build record before retrying: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Avoid modifying registry builds manually outside Packer","Keep all Packer clients writing to a bucket on a compatible version","Periodically audit long-lived buckets for malformed build records","Re-create versions rather than patching builds with unknown tooling"],"tags":["hcp-packer","data-conversion","build-record"],"backgroundTag":"api-response-decode-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"}