OpenNHP/opennhp · error

failed to read file content

Error message

failed to read file content: %w

What it means

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.

Solutions

  1. Check dmesg/kernel logs and mount health for the filesystem holding the file (look for EIO/stale NFS handle)
  2. Retry Md5sum after remounting or restoring the storage backend — this error is often transient
  3. Copy the file to local disk and hash the copy if the source is a network/fuse mount
  4. If persistent, replace the failing disk or restore the file from backup

Example fix

// before
sum, err := utils.Md5sum("/mnt/nfs/ta.so")
// after
local := filepath.Join(os.TempDir(), "ta.so")
if _, err := copyFile("/mnt/nfs/ta.so", local); err != nil {
    return err
}
sum, err := utils.Md5sum(local)
Defensive patterns

Strategy: retry

Try / catch

sum, err := utils.Md5sum(p); if err != nil { sum, err = utils.Md5sum(p) }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/c4a3e1568cc2481c. Report an issue: GitHub.

Appendix: source

Thrown at nhp/utils/crypto.go:143

	fileInfo, err := os.Stat(fullFilePath)
	if err != nil {
		return "", fmt.Errorf("file not found: %w", err)
	}

	if !fileInfo.Mode().IsRegular() {
		return "", fmt.Errorf("path is not a regular file")
	}

	file, err := os.Open(fullFilePath) //nolint:gosec // G304: Path validated by os.Stat above
	if err != nil {
		return "", fmt.Errorf("failed to open file: %w", err)
	}
	defer file.Close()

	hasher := md5.New()

	if _, err := io.Copy(hasher, file); err != nil {
		return "", fmt.Errorf("failed to read file content: %w", err)
	}

	// Convert hash to hex string
	return hex.EncodeToString(hasher.Sum(nil)), nil
}

View on GitHub (pinned to 6e04ca5ff0)