wavetermdev/waveterm · error

getting absolute path: %w

Error message

getting absolute path: %w

What it means

For non-URL arguments, viewRun resolves the target to an absolute path with filepath.Abs(fileArg) before constructing the create-block command. filepath.Abs only fails in exotic cases (e.g. working directory cannot be determined on Windows, or pathological input), and when it does the command wraps the error with this message.

Source

Thrown at cmd/wsh/cmd/wshcmd-view.go:78

	fileArg := args[0]
	conn := RpcContext.Conn
	var wshCmd *wshrpc.CommandCreateBlockData
	if strings.HasPrefix(fileArg, "http://") || strings.HasPrefix(fileArg, "https://") {
		wshCmd = &wshrpc.CommandCreateBlockData{
			TabId: tabId,
			BlockDef: &waveobj.BlockDef{
				Meta: map[string]any{
					waveobj.MetaKey_View: "web",
					waveobj.MetaKey_Url:  fileArg,
				},
			},
			Magnified: viewMagnified,
			Focused:   true,
		}
	} else {
		absFile, err := filepath.Abs(fileArg)
		if err != nil {
			return fmt.Errorf("getting absolute path: %w", err)
		}
		absParent, err := filepath.Abs(filepath.Dir(fileArg))
		if err != nil {
			return fmt.Errorf("getting absolute path of parent dir: %w", err)
		}
		_, err = os.Stat(absParent)
		if err == fs.ErrNotExist {
			return fmt.Errorf("parent directory does not exist: %q", absParent)
		}
		if err != nil {
			return fmt.Errorf("getting file info: %w", err)
		}
		wshCmd = &wshrpc.CommandCreateBlockData{
			TabId: tabId,
			BlockDef: &waveobj.BlockDef{
				Meta: map[string]interface{}{
					waveobj.MetaKey_View: "preview",
					waveobj.MetaKey_File: absFile,

View on GitHub (pinned to a4447c1563)

Solutions

  1. `cd` to a valid existing directory before running the command
  2. Verify the path string is well-formed for your OS (no NUL bytes/reserved names)
  3. If scripting, resolve the path yourself first and pass an absolute path

Example fix

// before
$ cd /tmp/deleted-dir && wsh view notes.md

// after
$ cd /home/user && wsh view notes.md
Defensive patterns

Strategy: validation

Validate before calling

# shell
TARGET=$(readlink -f "$1") || exit 1
wsh view "$TARGET"

Try / catch

try {
  err := viewRun(cmd, args)
  if err != nil && strings.Contains(err.Error(), "getting absolute path") {
    // fall back to an absolute path computed in a known-good cwd
  }
}

Prevention

When it happens

Trigger: Calling `wsh view <file>` when the process's current working directory cannot be resolved by os.Getwd (filepath.Abs depends on it for relative paths) — e.g. the cwd was deleted, or a Windows drive/path resolution failure.

Common situations: Running from a directory that was deleted while the shell still sits in it; corrupted cwd state in container/nspawn environments; extremely malformed path arguments on Windows (reserved device names).

Related errors


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