{"record":{"id":"dfb53651dbf4dbf7","repo":"hashicorp/packer","slug":"failed-to-hash-s","errorCode":null,"errorMessage":"Failed to hash: %s","messagePattern":"Failed to hash: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/plugin-getter/checksum.go","lineNumber":99,"sourceCode":"// ChecksumFile compares the expected checksum to the checksum of the file in\n// filePath using the hash function.\nfunc (c *Checksummer) ChecksumFile(expected []byte, filePath string) error {\n\tf, err := os.Open(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Checksum: failed to open file for checksum: %s\", err)\n\t}\n\tdefer f.Close()\n\terr = c.Checksum(expected, f)\n\tif cerr, ok := err.(*ChecksumError); ok {\n\t\tcerr.File = filePath\n\t}\n\treturn err\n}\n\nfunc (c *Checksummer) Sum(f io.Reader) ([]byte, error) {\n\tc.Hash.Reset()\n\tif _, err := io.Copy(c.Hash, f); err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed to hash: %s\", err)\n\t}\n\treturn c.Hash.Sum(nil), nil\n}\n\nfunc (c *Checksummer) Checksum(expected []byte, f io.Reader) error {\n\tactual, err := c.Sum(f)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !bytes.Equal(actual, expected) {\n\t\treturn &ChecksumError{\n\t\t\tHash:     c.Hash,\n\t\t\tActual:   actual,\n\t\t\tExpected: expected,\n\t\t}\n\t}\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/plugin-getter/checksum.go#L81-L117","documentation":"Checksummer.Sum reads the whole stream with io.Copy into the configured hash and returns this error when the read fails mid-stream. It wraps the reader's I/O error, meaning hashing aborted because the input could not be fully read.","triggerScenarios":"Called by Checksum (during plugin verification) or generateMockChecksumFile when the io.Reader (file, HTTP body) returns a read error: network drop mid-download of a checksummed stream, file descriptor closed, or an unreadable file region (I/O error on disk).","commonSituations":"Unstable network while streaming plugin downloads; a truncated file on a failing disk; piping from a process that exited early; reading from a network mount that dropped.","solutions":["Retry the download/install — transient network errors usually resolve.","Re-download the file and verify checksum again; the local copy may be truncated.","Check disk health (dmesg/smartctl) if local file reads fail repeatedly.","Avoid piping from short-lived processes; hash from a fully written file."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if f, ok := r.(*os.File); ok {\n    if fi, err := f.Stat(); err == nil && !fi.Mode().IsRegular() { /* warn: non-regular file may fail mid-read */ }\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    sum, err := cs.Sum(openStream())\n    if err == nil { break }\n    time.Sleep(backoff(attempt))\n}","preventionTips":["Retry transient hash/read failures with backoff, especially over HTTP streams.","Prefer hashing a fully-written local file over a live network stream.","Monitor disk health if local reads repeatedly fail."],"tags":["io","checksum","network"],"backgroundTag":"io-read-failure","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"}