wavetermdev/waveterm · error

getting file stats: %w

Error message

getting file stats: %w

What it means

tailLogFile could not Stat the opened log file, which it needs to compute the read offset (last 16KB). With the file already open this is rare and usually means the underlying file vanished or an OS-level I/O problem occurred.

Source

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

		}
		return nil
	}

	WriteStdout("%s\n", path)
	return nil
}

func tailLogFile(path string) error {
	file, err := os.Open(path)
	if err != nil {
		return fmt.Errorf("opening log file: %w", err)
	}
	defer file.Close()

	// Get file size
	stat, err := file.Stat()
	if err != nil {
		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)

View on GitHub (pinned to a4447c1563)

Solutions

  1. Re-run the command; transient races resolve on retry.
  2. Check the log directory is on a healthy local filesystem.
  3. Check system fd/memory limits (`ulimit`).
  4. Skip tailing and print the path with `wsh wavepath log`.

Example fix

// before
stat, err := file.Stat()
// after
stat, err := file.Stat()
if err != nil { return fmt.Errorf("getting file stats (was the log rotated?): %w", err) }
Defensive patterns

Strategy: retry

Try / catch

stat, err := file.Stat()
if err != nil {
    if _, reopenErr := os.Open(path); reopenErr == nil { return retryTail(path) }
    return fmt.Errorf("getting file stats: %w", err)
}

Prevention

When it happens

Trigger: File deleted/rotated between os.Open and Stat (race), file on a network/FUSE mount returning stat errors, or fd exhaustion causing odd failures.

Common situations: Aggressive log rotation racing with `wsh wavepath log --tail`; unmounted network volumes hosting the Wave data dir.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/9217d1576c50f00e. Report an issue: GitHub.