{"record":{"id":"c5d092d4972cb9a9","repo":"gohugoio/hugo","slug":"failed-to-calculate-hash-w","errorCode":null,"errorMessage":"failed to calculate hash: %w","messagePattern":"failed to calculate hash: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource.go","lineNumber":681,"sourceCode":"\tvalue    uint64\n\tsize     int64\n\tinitOnce sync.Once\n}\n\nfunc (r *resourceHash) init(l hugio.ReadSeekCloserProvider) error {\n\tvar initErr error\n\tr.initOnce.Do(func() {\n\t\tvar hash uint64\n\t\tvar size int64\n\t\tf, err := l.ReadSeekCloser()\n\t\tif err != nil {\n\t\t\tinitErr = fmt.Errorf(\"failed to open source: %w\", err)\n\t\t\treturn\n\t\t}\n\t\tdefer f.Close()\n\t\thash, size, err = hashImage(f)\n\t\tif err != nil {\n\t\t\tinitErr = fmt.Errorf(\"failed to calculate hash: %w\", err)\n\t\t\treturn\n\t\t}\n\t\tr.value = hash\n\t\tr.size = size\n\t})\n\n\treturn initErr\n}\n\nfunc hashImage(r io.ReadSeeker) (uint64, int64, error) {\n\treturn hashing.XXHashFromReader(r)\n}\n\n// InternalResourceTargetPath is used internally to get the target path for a Resource.\nfunc InternalResourceTargetPath(r resource.Resource) string {\n\treturn r.(targetPathProvider).targetPath()\n}\n","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource.go#L663-L699","documentation":"Wrapped error from `resourceHash.init` (resource.go:679-682) when `hashImage` fails to compute xxhash from the open reader. `hashImage` delegates to `hashing.XXHashFromReader`; failure means the reader returned an error mid-read (truncated file, network-blip on remote reader, mid-read disk failure). Distinct from 586: source opened but bytes could not be hashed.","triggerScenarios":"Source opens successfully but errors during the actual read inside `XXHashFromReader` -- partial download, file truncated by another writer, read timeout on a remote-backed reader, disk I/O error mid-stream.","commonSituations":"File being written concurrently while Hugo hashes it (asset pipeline mid-build); NFS/SMB hiccup mid-read; remote resource partial fetch where the reader yields EOF early or returns an error after some bytes; corrupted file on disk.","solutions":["Re-fetch or restore the source asset so it is complete and stable during the build.","Run the build with no concurrent writers touching `assets/`/`resources/`/`static/`.","For remote resources, raise `timeout` and confirm the server returns full Content-Length.","Run `hugo --gc` to evict any half-written cached resource.","Check dmesg / disk health if read errors recur on local files."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Retry hash on transient read errors.\nvar res resource.Resource\nvar err error\nfor i := 0; i < 3; i++ {\n\tres, err = rs.NewResource(...)\n\tif err == nil || !strings.Contains(err.Error(), \"failed to calculate hash\") {\n\t\tbreak\n\t}\n\ttime.Sleep(time.Duration(i+1) * time.Second)\n}","preventionTips":["Don't write to asset files concurrently with builds.","Pin remote assets to known-good versions when possible.","Run `hugo --gc` to evict half-written cached resources."],"tags":["resources","io","hash","filesystem","network"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}