{"record":{"id":"e88c299ab7aefefa","repo":"hashicorp/packer","slug":"unable-to-parse-content-from-s-s","errorCode":null,"errorMessage":"Unable to parse content from %s: %s","messagePattern":"Unable to parse content from (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/manifest/post-processor.go","lineNumber":153,"sourceCode":"\t\t_, err = os.OpenFile(lockFilename, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)\n\t\tif err == nil {\n\t\t\tbreak\n\t\t}\n\t\tlog.Printf(\"Error locking manifest file for reading and writing. Will sleep and retry. %s\", err)\n\t}\n\tdefer os.Remove(lockFilename)\n\n\t// Read the current manifest file from disk\n\tvar contents []byte\n\tif contents, err = os.ReadFile(p.config.OutputPath); err != nil && !os.IsNotExist(err) {\n\t\treturn source, true, true, fmt.Errorf(\"Unable to open %s for reading: %s\", p.config.OutputPath, err)\n\t}\n\n\t// Parse the manifest file JSON, if we have one\n\tmanifestFile := &ManifestFile{}\n\tif len(contents) > 0 {\n\t\tif err = json.Unmarshal(contents, manifestFile); err != nil {\n\t\t\treturn source, true, true, fmt.Errorf(\"Unable to parse content from %s: %s\", p.config.OutputPath, err)\n\t\t}\n\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}","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/manifest/post-processor.go#L135-L171","documentation":"After reading the manifest file, the post-processor unmarshals its JSON into a ManifestFile struct. If the existing packer-manifest.json contains invalid or unexpected JSON, json.Unmarshal fails and PostProcess aborts with this error. This guards against a corrupted or hand-broken manifest.","triggerScenarios":"json.Unmarshal(contents, manifestFile) returns an error — the existing output file is truncated, manually edited into invalid JSON, contains a different JSON schema (e.g. another tool's output written to the same path), or has a UTF-8/BOM issue.","commonSituations":"A previous run was killed mid-write leaving a truncated manifest; a user hand-edited packer-manifest.json and broke the syntax; output_path collides with another tool's JSON file.","solutions":["Delete or rename the corrupt packer-manifest.json and re-run; a fresh one is created automatically.","Validate the file with `jq . packer-manifest.json` to see the exact syntax error if you want to repair it by hand.","Point output_path at a dedicated file to avoid collisions with other tools' output.","Avoid killing packer mid-post-process; let the manifest write complete."],"exampleFix":"// before: hand-edited manifest with trailing comma\n{\"builds\": [{...},], \"last_run_uuid\": \"...\"}\n// after: restore valid JSON or remove the file\nrm packer-manifest.json && packer build template.pkr.hcl","handlingStrategy":"fallback","validationCode":"# detect a corrupt manifest before building\njq -e . packer-manifest.json > /dev/null 2>&1 || { echo 'corrupt manifest, removing'; rm -f packer-manifest.json; }","typeGuard":"function isParsableManifest(path) {\n  try { JSON.parse(fs.readFileSync(path, 'utf8')); return true } catch { return false }\n}","tryCatchPattern":"// wrapper around packer run\ntry {\n  execSync('packer build template.pkr.hcl')\n} catch (e) {\n  if (/Unable to parse content from/.test(e.message)) {\n    fs.rmSync('packer-manifest.json');\n    execSync('packer build template.pkr.hcl'); // regenerate\n  } else throw e;\n}","preventionTips":["Never hand-edit packer-manifest.json.","Don't write other tools' JSON to the same output_path.","Let packer finish post-processing; avoid killing mid-run.","Validate existing manifests with jq before builds."],"tags":["json","manifest","post-processor","parse-error"],"backgroundTag":"json-parse-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"}