wavetermdev/waveterm · error

reading file: %w

Error message

reading file: %w

What it means

fileCatRun wraps any error from streamReadFromFile with 'reading file:'. This is the top-level wrapper for `wsh file cat`; the underlying cause is one of the streamReadFromFile failures (no info, no route id, path parse error, stream start failure, or io.Copy failure).

Source

Thrown at cmd/wsh/cmd/wshcmd-file.go:181

	Example: "  wsh file mv wsh://user@ec2/home/user/config.txt ./local-config.txt\n  wsh file mv ./local-config.txt wsh://user@ec2/home/user/config.txt",
	Args:    cobra.ExactArgs(2),
	RunE:    activityWrap("file", fileMvRun),
	PreRunE: preRunSetupRpcClient,
}

func fileCatRun(cmd *cobra.Command, args []string) error {
	path, err := fixRelativePaths(args[0])
	if err != nil {
		return err
	}

	fileData := wshrpc.FileData{
		Info: &wshrpc.FileInfo{
			Path: path}}

	err = streamReadFromFile(cmd.Context(), fileData, os.Stdout)
	if err != nil {
		return fmt.Errorf("reading file: %w", err)
	}

	return nil
}

func fileInfoRun(cmd *cobra.Command, args []string) error {
	path, err := fixRelativePaths(args[0])
	if err != nil {
		return err
	}
	fileData := wshrpc.FileData{
		Info: &wshrpc.FileInfo{
			Path: path}}

	info, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
	err = convertNotFoundErr(err)
	if err != nil {
		return fmt.Errorf("getting file info: %w", err)

View on GitHub (pinned to a4447c1563)

Solutions

  1. Read the wrapped cause: fix per the inner error (route id, path parse, or stream start).
  2. Confirm the file exists remotely with `wsh file info <path>` first.
  3. Re-run with a stable connection; avoid cancelling or killing the CLI mid-stream.
Defensive patterns

Strategy: try-catch

Validate before calling

info, err := wshclient.FileInfoCommand(RpcClient, &wshrpc.FileData{Info: &wshrpc.FileInfo{Path: path}}, &wshrpc.RpcOpts{Timeout: fileTimeout})
if err != nil || info.NotFound {
    return fmt.Errorf("cannot cat %q: missing or unreachable", path)
}

Try / catch

if err := streamReadFromFile(cmd.Context(), fileData, os.Stdout); err != nil {
    switch {
    case strings.Contains(err.Error(), "no route id"):
        // fix connection
    case strings.Contains(err.Error(), "parsing file path"):
        // fix URI
    default:
        // stream failure: retry or report
    }
    return fmt.Errorf("reading file: %w", err)
}

Prevention

When it happens

Trigger: `wsh file cat <path>` where the underlying stream fails: invalid path URI, no RPC connection, remote file missing/unreadable, or interruption of the stream copy (ctx cancelled, connection reset).

Common situations: Catting a nonexistent remote file, running wsh outside a terminal with no RPC broker, network drop mid-transfer, hitting Ctrl-C partway (context cancelled).

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/dea3f4b18a7ac57c. Report an issue: GitHub.