wavetermdev/waveterm · error

creating file: %w

Error message

creating file: %w

What it means

ensureFile first checks whether the target file exists via FileInfoCommand; if it reports not-found (fs.ErrNotExist), it attempts to create it with FileCreateCommand. This error wraps a failure of that create RPC — the file was absent AND could not be created.

Source

Thrown at cmd/wsh/cmd/wshcmd-file-util.go:37

)

func convertNotFoundErr(err error) error {
	if err == nil {
		return nil
	}
	if strings.HasPrefix(err.Error(), "NOTFOUND:") {
		return fs.ErrNotExist
	}
	return err
}

func ensureFile(fileData wshrpc.FileData) (*wshrpc.FileInfo, error) {
	info, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
	err = convertNotFoundErr(err)
	if err == fs.ErrNotExist {
		err = wshclient.FileCreateCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
		if err != nil {
			return nil, fmt.Errorf("creating file: %w", err)
		}
		info, err = wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
		if err != nil {
			return nil, fmt.Errorf("getting file info: %w", err)
		}
		return info, err
	}
	if err != nil {
		return nil, fmt.Errorf("getting file info: %w", err)
	}
	return info, nil
}

func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {
	// First truncate the file with an empty write
	emptyWrite := fileData
	emptyWrite.Data64 = ""
	err := wshclient.FileWriteCommand(RpcClient, emptyWrite, &wshrpc.RpcOpts{Timeout: fileTimeout})

View on GitHub (pinned to a4447c1563)

Solutions

  1. Create the parent directory first (e.g. `wsh mkdir` or manually) and re-run the append.
  2. Check write permissions on the target directory for your user on the target host.
  3. Verify the file path/URI is correct and the remote connection is up (`wsh connection check`).
  4. Create the file manually (touch) before running the append command.

Example fix

// before
wsh append /no/such/dir/log.txt
// after
wsh mkdir /no/such/dir && wsh append /no/such/dir/log.txt
Defensive patterns

Strategy: try-catch

Validate before calling

parentDir := filepath.Dir(path)
if info, err := wshclient.FileInfoCommand(RpcClient, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: parentDir}}, &wshrpc.RpcOpts{Timeout: fileTimeout}); err != nil {
    return fmt.Errorf("parent directory missing or unreadable: %w", err)
}

Try / catch

info, err := ensureFile(fileData)
if err != nil && strings.Contains(err.Error(), "creating file") {
    // handle: create parent dir, fix permissions, then retry
}

Prevention

When it happens

Trigger: `wsh append <file>` (fileAppendRun) on a path whose FileInfoCommand returned NOTFOUND, and then FileCreateCommand fails: invalid path, permission denied on the remote, parent directory missing, or read-only filesystem.

Common situations: Appending to a file in a directory that does not exist remotely; no write permission for the connecting user; typo in the path; trying to create a file on a connection that is offline.

Related errors


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