wavetermdev/waveterm · error

reading file: %w

Error message

reading file: %w

What it means

After seeking, tailLogFile's Read on the log file returned a non-EOF error, so it cannot deliver the buffered tail of the log. EOF is deliberately tolerated since Read at EOF is expected for small files.

Source

Thrown at cmd/wsh/cmd/wshcmd-wavepath.go:114

		return fmt.Errorf("getting file stats: %w", err)
	}

	// Read last 16KB or whole file if smaller
	readSize := int64(16 * 1024)
	var offset int64
	if stat.Size() > readSize {
		offset = stat.Size() - readSize
	}

	_, err = file.Seek(offset, 0)
	if err != nil {
		return fmt.Errorf("seeking file: %w", err)
	}

	buf := make([]byte, readSize)
	n, err := file.Read(buf)
	if err != nil && err != io.EOF {
		return fmt.Errorf("reading file: %w", err)
	}
	buf = buf[:n]

	// Skip partial line at start if we're not at beginning of file
	if offset > 0 {
		idx := bytes.IndexByte(buf, '\n')
		if idx >= 0 {
			buf = buf[idx+1:]
		}
	}

	// Split into lines
	lines := bytes.Split(buf, []byte{'\n'})

	// Take last 100 lines if we have more
	startIdx := 0
	if len(lines) > 100 {
		startIdx = len(lines) - 100

View on GitHub (pinned to a4447c1563)

Solutions

  1. Re-run the command; rotation races are transient.
  2. Check `dmesg`/system logs for disk I/O errors.
  3. Move logs to a local disk instead of a network mount.
  4. Use `wsh wavepath log` (no --tail) and tail with system tools.

Example fix

// before
n, err := file.Read(buf)
if err != nil && err != io.EOF { return fmt.Errorf("reading file: %w", err) }
// after
n, err := io.ReadFull(file, buf)
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { return fmt.Errorf("reading file: %w", err) }
Defensive patterns

Strategy: retry

Try / catch

n, err := file.Read(buf)
if err != nil && err != io.EOF {
    if isTransient(err) { return retryTail(path) }
    return fmt.Errorf("reading file: %w", err)
}

Prevention

When it happens

Trigger: `wsh wavepath log --tail` when the underlying file disappears mid-read (rotation/delete), hardware or network I/O error, or interruption while reading from an unstable mount.

Common situations: Log rotation racing the read, disks dropping errors, or reading logs over SSHFS/NFS mounts that time out.

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 wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/0d4ba993d7b9ffa9. Report an issue: GitHub.