{"record":{"id":"c4a3e1568cc2481c","repo":"OpenNHP/opennhp","slug":"failed-to-read-file-content-w","errorCode":null,"errorMessage":"failed to read file content: %w","messagePattern":"failed to read file content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/crypto.go","lineNumber":143,"sourceCode":"\tfileInfo, err := os.Stat(fullFilePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"file not found: %w\", err)\n\t}\n\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"path is not a regular file\")\n\t}\n\n\tfile, err := os.Open(fullFilePath) //nolint:gosec // G304: Path validated by os.Stat above\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\thasher := md5.New()\n\n\tif _, err := io.Copy(hasher, file); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read file content: %w\", err)\n\t}\n\n\t// Convert hash to hex string\n\treturn hex.EncodeToString(hasher.Sum(nil)), nil\n}\n","sourceCodeStart":125,"sourceCodeEnd":149,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/crypto.go#L125-L149","documentation":"Md5sum streams the open file into the MD5 hasher with io.Copy. If any read from the file fails mid-stream (I/O error, media failure, truncated network filesystem), the underlying error is wrapped as \"failed to read file content: %w\". By this point Stat and Open already succeeded, so the problem is in the read itself, not lookup or permission at open time.","triggerScenarios":"The file is on a failing or disconnected disk/NFS mount; the file was truncated or the device returned EIO during the copy; a FUSE/network filesystem dropped the connection while reading; reading a sparse or special file that errors mid-stream.","commonSituations":"NFS stale handle after the storage backend re-exported; EIO from a failing disk in dmesg; container volume detached mid-read; flaky VPN-mounted remote share.","solutions":["Check dmesg/kernel logs and mount health for the filesystem holding the file (look for EIO/stale NFS handle)","Retry Md5sum after remounting or restoring the storage backend — this error is often transient","Copy the file to local disk and hash the copy if the source is a network/fuse mount","If persistent, replace the failing disk or restore the file from backup"],"exampleFix":"// before\nsum, err := utils.Md5sum(\"/mnt/nfs/ta.so\")\n// after\nlocal := filepath.Join(os.TempDir(), \"ta.so\")\nif _, err := copyFile(\"/mnt/nfs/ta.so\", local); err != nil {\n    return err\n}\nsum, err := utils.Md5sum(local)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"sum, err := utils.Md5sum(p); if err != nil { sum, err = utils.Md5sum(p) }","preventionTips":["Prefer local disk for integrity-checked files"],"tags":["go","filesystem","io","md5"],"backgroundTag":"file-read-failed","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}