{"record":{"id":"5fd603b0f8195821","repo":"hashicorp/packer","slug":"failed-to-create-decoder-for-hcp-packer-artifact","errorCode":null,"errorMessage":"failed to create decoder for HCP Packer artifact: %w","messagePattern":"failed to create decoder for HCP Packer artifact: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":773,"sourceCode":"\treturn artifacts, err\n}\n\nfunc (bucket *Bucket) doCompleteBuild(\n\tctx context.Context,\n\tbuildName string,\n\tpackerSDKArtifacts []packerSDK.Artifact,\n\tui packerSDK.Ui,\n\tbuildErr error,\n) ([]packerSDK.Artifact, error) {\n\tfor _, art := range packerSDKArtifacts {\n\t\tvar sdkImages []packerSDKRegistry.Image\n\t\tdecoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{\n\t\t\tResult:           &sdkImages,\n\t\t\tWeaklyTypedInput: true,\n\t\t\tErrorUnused:      false,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn packerSDKArtifacts, fmt.Errorf(\n\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 {","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L755-L791","documentation":"doCompleteBuild uses a mapstructure decoder to convert each artifact's HCP state into []packerSDKRegistry.Image. If mapstructure.NewDecoder itself fails — which for this fixed configuration essentially only happens with an invalid decoder config (e.g. Result not a settable pointer) — the artifact upload aborts with this wrapped error. In practice this is almost always an internal/programming error rather than a user misconfiguration.","triggerScenarios":"Bucket.CompleteBuild -> doCompleteBuild constructs mapstructure.NewDecoder with Result pointing at &sdkImages; the constructor returns an error (misconfigured DecoderConfig), triggering the wrapped return.","commonSituations":"Code changes to the decoder configuration in a forked/patched Packer or plugin SDK that make the config invalid; virtually never hit by end users running stock Packer.","solutions":["Report as a Packer bug with the full output (github.com/hashicorp/packer/issues)","If using a fork or patch, revert changes to the mapstructure.DecoderConfig in doCompleteBuild","Ensure packer-plugin-sdk and mapstructure dependency versions are consistent when building from source"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Only relevant when patching Packer: unit-test the decoder config\n// dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{Result: &imgs, WeaklyTypedInput: true})\n// if err != nil { t.Fatalf(\"decoder config invalid: %v\", err) }","typeGuard":"// Go: assert the decode target is a valid settable pointer\nfunc validDecoderTarget(p interface{}) bool {\n\tv := reflect.ValueOf(p)\n\treturn v.Kind() == reflect.Ptr && !v.IsNil() && v.Elem().CanSet()\n}","tryCatchPattern":"// Go\n_, err := bucket.CompleteBuild(ctx, buildName, arts, ui, nil)\nif err != nil && strings.Contains(err.Error(), \"failed to create decoder\") {\n\t// internal bug path: file an issue at github.com/hashicorp/packer/issues\n\treturn fmt.Errorf(\"packer internal error, please report: %w\", err)\n}","preventionTips":["Run stock Packer releases; avoid forks with modified decoder configuration","Keep packer-plugin-sdk and mapstructure versions aligned when building from source","Report this error upstream — it indicates invalid internal configuration, not user error"],"tags":["hcp-packer","mapstructure","internal-bug","decoder"],"backgroundTag":"decoder-creation-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"}