{"record":{"id":"354e7684d77c9ecd","repo":"hashicorp/packer","slug":"unable-to-compute-s-hash-for-s","errorCode":null,"errorMessage":"unable to compute %s hash for %s","messagePattern":"unable to compute (.+?) hash for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/checksum/post-processor.go","lineNumber":151,"sourceCode":"\t\t\t\tnewartifact.files = append(newartifact.files, checksumFile)\n\t\t\t}\n\t\t\tif err := os.MkdirAll(filepath.Dir(checksumFile), os.FileMode(0755)); err != nil {\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to create dir: %s\", err.Error())\n\t\t\t}\n\t\t\tfw, err := os.OpenFile(checksumFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0644))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to create file %s: %s\", checksumFile, err.Error())\n\t\t\t}\n\t\t\tfr, err := os.Open(art)\n\t\t\tif err != nil {\n\t\t\t\tfw.Close()\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to open file %s: %s\", art, err.Error())\n\t\t\t}\n\n\t\t\tif _, err = io.Copy(h, fr); err != nil {\n\t\t\t\tfr.Close()\n\t\t\t\tfw.Close()\n\t\t\t\treturn nil, false, true, fmt.Errorf(\"unable to compute %s hash for %s\", ct, art)\n\t\t\t}\n\t\t\tfr.Close()\n\t\t\t_, _ = fw.WriteString(fmt.Sprintf(\"%x\\t%s\\n\", h.Sum(nil), filepath.Base(art)))\n\t\t\tfw.Close()\n\t\t\th.Reset()\n\t\t}\n\t}\n\n\t// sets keep and forceOverride to true because we don't want to accidentally\n\t// delete the very artifact we're checksumming.\n\treturn newartifact, true, true, nil\n}\n","sourceCodeStart":133,"sourceCodeEnd":164,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/checksum/post-processor.go#L133-L164","documentation":"The checksum post-processor failed while copying the artifact file into the hash writer (io.Copy to hash.Hash). It wraps any read/compute failure into a single message naming the checksum type and the artifact path, so the original OS error is lost and must be inferred.","triggerScenarios":"io.Copy(h, fr) returns an error while hashing the artifact file in PostProcess — typically an I/O read failure (disk error, file truncated/removed between open and read, permissions changed mid-read) or a hash writer write panic-path failure.","commonSituations":"Running on a full or failing disk; artifact file deleted or shrunk by a later post-processor before checksum runs; network/shared filesystem (NFS/SMB) drop while reading a remotely stored artifact; SELinux/AppArmor denying reads.","solutions":["Re-run packer to rule out a transient I/O error","Verify the artifact file exists, is readable, and is not being mutated concurrently (chmod/ls -l, check no parallel post-processor deletes it)","Check disk health/space (dmesg, df) on the output filesystem","If on a network filesystem, copy the artifact locally before the checksum post-processor"],"exampleFix":"// before: original io error is swallowed\nreturn nil, false, true, fmt.Errorf(\"unable to compute %s hash for %s\", ct, art)\n// after: preserve cause for diagnosis\nreturn nil, false, true, fmt.Errorf(\"unable to compute %s hash for %s: %w\", ct, art, err)","handlingStrategy":"try-catch","validationCode":"stat, err := os.Stat(artifactPath)\nif err != nil || !stat.Mode().IsRegular() {\n    return fmt.Errorf(\"artifact not readable: %w\", err)\n}\n// also ensure free disk space and no concurrent writers to the file","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) {\n        // inspect pe.Op/pe.Path to diagnose read failure\n    }\n    // retry once on transient I/O errors before failing the build\n}","preventionTips":["Verify artifact file exists and is a regular file before checksum runs","Avoid post-processor chains that delete or rewrite the artifact concurrently","Monitor disk health and free space on the output filesystem","Run checksums on local storage rather than flaky network mounts"],"tags":["io","checksum","post-processor","filesystem"],"backgroundTag":"file-read-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"}