hashicorp/packer · error
Unable to load existing build for %q: %v
Error message
Unable to load existing build for %q: %v
What it means
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.
Source
Thrown at internal/hcp/registry/types.bucket.go:538
// All build details will be created (if they don't exist) and added to b.Version.builds for tracking during runtime.
func (bucket *Bucket) populateVersion(ctx context.Context) error {
// list all this version's builds so we can figure out which ones
// we want to run against. TODO: pagination?
existingBuilds, err := bucket.client.ListBuilds(ctx, bucket.Name, bucket.Version.Fingerprint)
if err != nil {
return fmt.Errorf("error listing builds for this existing version: %s", err)
}
var toCreate []string
for _, expected := range bucket.Version.expectedBuilds {
var found bool
for _, existing := range existingBuilds {
if existing.ComponentType == expected {
found = true
build, err := NewBuildFromCloudPackerBuild(existing)
if err != nil {
return fmt.Errorf("Unable to load existing build for %q: %v", existing.ComponentType, err)
}
// When running against an existing build the Packer RunUUID is most likely different.
// We capture that difference here to know that the artifacts were created in a different Packer run.
build.RunUUID = bucket.Version.RunUUID
// When bucket build labels represent some dynamic data set, possibly set via some user variable,
// we need to make sure that any newly executed builds get the labels at runtime.
if build.IsNotDone() && len(bucket.BuildLabels) > 0 {
build.MergeLabels(bucket.BuildLabels)
}
log.Printf(
"[TRACE] a build of component type %s already exists; skipping the create call", expected,
)
bucket.Version.StoreBuild(existing.ComponentType, build)
breakView on GitHub (pinned to eb36e3c3e4)
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
Defensive patterns
Strategy: type-guard
Validate before calling
// Inspect existing builds before initializing and skip malformed records
// builds, err := client.ListBuilds(ctx, bucketName, fingerprint)
// for _, b := range builds {
// if b.ID == nil || b.ID.IsZero() || b.ComponentType == "" {
// // repair or delete this build record in HCP before running
// }
// } Type guard
// Go: validate the cloud build before conversion
func usableCloudBuild(b *hcpPackerModels.HashicorpCloudPacker20230101Build) bool {
return b != nil && b.ID != nil && !b.ID.IsZero() && b.ComponentType != ""
} Try / catch
// Go
if err := bucket.Initialize(ctx); err != nil {
if strings.Contains(err.Error(), "Unable to load existing build") {
// corrupted build record: delete the build/version in HCP and re-run
return fmt.Errorf("repair the HCP build record before retrying: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- error retrieving version from HCP Packer Registry: %s
- error retrieving channel from HCP Packer Registry: %s
- there is no version associated with the channel %s
- the version %s is revoked and can not be used on Packer buil
- could not find a build result matching [region=%q, platform=
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/92f9ba9d9f53cb17.
Report an issue: GitHub.