{"record":{"id":"0202176a3af82b4d","repo":"hashicorp/packer","slug":"unable-to-marshal-json-s","errorCode":null,"errorMessage":"Unable to marshal JSON %s","messagePattern":"Unable to marshal JSON (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"post-processor/manifest/post-processor.go","lineNumber":173,"sourceCode":"\t}\n\n\t// If -force is set and we are not on same run, truncate the file. Otherwise\n\t// we will continue to add new builds to the existing manifest file.\n\tif p.config.PackerForce && os.Getenv(\"PACKER_RUN_UUID\") != manifestFile.LastRunUUID {\n\t\tmanifestFile = &ManifestFile{}\n\t}\n\n\t// Add the current artifact to the manifest file\n\tmanifestFile.Builds = append(manifestFile.Builds, *artifact)\n\tmanifestFile.LastRunUUID = os.Getenv(\"PACKER_RUN_UUID\")\n\n\t// Write JSON to disk\n\tif out, err := json.MarshalIndent(manifestFile, \"\", \"  \"); err == nil {\n\t\tif err = os.WriteFile(p.config.OutputPath, out, 0664); err != nil {\n\t\t\treturn source, true, true, fmt.Errorf(\"Unable to write %s: %s\", p.config.OutputPath, err)\n\t\t}\n\t} else {\n\t\treturn source, true, true, fmt.Errorf(\"Unable to marshal JSON %s\", err)\n\t}\n\n\t// The manifest should never delete the artifacts it is set to record, so it\n\t// forcibly sets \"keep\" to true.\n\treturn source, true, true, nil\n}\n\nfunc createInterpolatedCustomData(config *Config, customData string) (string, error) {\n\tinterpolatedCmd, err := interpolate.Render(customData, &config.ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error interpolating custom data: %s\", err)\n\t}\n\treturn interpolatedCmd, nil\n}\n","sourceCodeStart":155,"sourceCodeEnd":188,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/manifest/post-processor.go#L155-L188","documentation":"Before writing the manifest, json.MarshalIndent converts the ManifestFile struct to pretty-printed JSON. If marshaling fails, this error is returned. Marshal only fails if the struct contains unsupported values (e.g. channels, funcs, cycles), which in practice indicates a plugin/SDK-level bug or a custom artifact exposing unsupported data rather than a user configuration mistake.","triggerScenarios":"json.MarshalIndent(manifestFile, \"\", \"  \") returns an error — an artifact's builder data/state or post-processor fields contain a value JSON cannot encode (func, channel, cycle), typically via custom artifact implementations.","commonSituations":"Rare; seen with custom/third-party builder plugins whose artifact State() returns non-JSON-serializable values, or SDK version mismatches introducing unsupported fields.","solutions":["Identify which plugin produced the artifact and check for updates — this usually indicates a plugin bug.","Report the issue to the custom builder/post-processor plugin maintainer with the full error text.","Try a released, official builder to confirm the manifest post-processor itself is fine.","Pin compatible versions of packer and the plugin (packer init / required_plugins) to rule out SDK drift."],"exampleFix":"// before (custom builder returns func in State)\nfunc (a *Artifact) State(id string) interface{} { return map[string]interface{}{\"fn\": a.closeFn} }\n// after\nfunc (a *Artifact) State(id string) interface{} { return map[string]interface{}{\"id\": a.id} }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// JSON-encode artifact state in plugin code before it reaches the manifest\nif data, err := json.Marshal(artifactState); err != nil {\n    log.Printf(\"artifact state not serializable: %v\", err)\n}","preventionTips":["Keep only JSON-serializable values in custom artifact State() maps.","Test custom builders with the manifest post-processor attached.","Keep packer and plugins version-compatible via required_plugins.","Report marshal failures with full output to the plugin maintainer."],"tags":["json","manifest","post-processor","serialization"],"backgroundTag":"json-marshal-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"}