hashicorp/packer · error

the build for the component %q does not appear to be a valid

Error message

the build for the component %q does not appear to be a valid registry Build

What it means

Returned by Version.Build when the entry stored under buildName exists but is not a *Build. This indicates the version's internal build map holds an unexpected type — a programming/pointer-aliasing bug rather than a user error.

Source

Thrown at internal/hcp/registry/types.version.go:82

	return nil
}

// StoreBuild stores a build for buildName to an active version.
func (version *Version) StoreBuild(buildName string, build *Build) {
	version.builds.Store(buildName, build)
}

// Build gets the store build associated with buildName in the active version.
func (version *Version) Build(buildName string) (*Build, error) {
	build, ok := version.builds.Load(buildName)
	if !ok {
		return nil, errors.New("no associated build found for the name " + buildName)
	}

	b, ok := build.(*Build)
	if !ok {
		return nil, fmt.Errorf("the build for the component %q does not appear to be a valid registry Build", buildName)
	}

	return b, nil
}

// HasBuild checks if version has a stored build associated with buildName.
func (version *Version) HasBuild(buildName string) bool {
	_, ok := version.builds.Load(buildName)

	return ok
}

// AddArtifactToBuild appends one or more artifacts to the build referred to by buildName.
func (version *Version) AddArtifactToBuild(buildName string, artifacts ...packerSDKRegistry.Image) error {
	build, err := version.Build(buildName)
	if err != nil {
		return fmt.Errorf("AddArtifactToBuild: %w", err)
	}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Do not mutate version.builds directly; only use StoreBuild with *Build values
  2. Check for data races around the Version object (run with -race)
  3. Upgrade Packer if this occurs during a normal build — it indicates a Packer bug
  4. Verify no plugin code inserts foreign types into the registry version
Defensive patterns

Strategy: type-guard

Validate before calling

// Only insert builds via StoreBuild with *Build values
version.StoreBuild(name, &Build{ComponentType: name})

Type guard

func isRegistryBuild(v interface{}) (*Build, bool) {
    b, ok := v.(*Build)
    return b, ok
}

Try / catch

b, err := version.Build(name)
if err != nil && strings.Contains(err.Error(), "does not appear to be a valid registry Build") {
    // internal state corruption: report bug, recreate the version
}

Prevention

When it happens

Trigger: version.builds[buildName] contains a non-*Build value while iterating or after concurrent mutation; reached from UpdateBuildStatus, uploadSbom, markBuildComplete, IsExpectingBuildForComponent, HeartbeatBuild, and doCompleteBuild.

Common situations: Concurrent modification of the version's build map without proper synchronization; custom code storing other types into version.builds; memory corruption via unsafe sharing across goroutines.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/db7c492c7a0d25de. Report an issue: GitHub.