wavetermdev/waveterm · error

getting absolute path for %s: %w

Error message

getting absolute path for %s: %w

What it means

Wraps filepath.Abs(filePath) failure while processing a `wsh ai` file argument. filepath.Abs rarely fails — it only errors when os.Getwd() fails, i.e. the current working directory has been deleted or is otherwise unresolvable. The wrapped error is preserved via %w.

Source

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

			if stdinUsed {
				return fmt.Errorf("stdin (-) can only be used once")
			}
			stdinUsed = true

			data, err = io.ReadAll(os.Stdin)
			if err != nil {
				return fmt.Errorf("reading from stdin: %w", err)
			}
			fileName = "stdin"
			mimeType = "text/plain"
		} else {
			fileInfo, err := os.Stat(filePath)
			if err != nil {
				return fmt.Errorf("accessing file %s: %w", filePath, err)
			}
			absPath, err := filepath.Abs(filePath)
			if err != nil {
				return fmt.Errorf("getting absolute path for %s: %w", filePath, err)
			}

			if fileInfo.IsDir() {
				result, err := fileutil.ReadDir(filePath, 500)
				if err != nil {
					return fmt.Errorf("reading directory %s: %w", filePath, err)
				}
				jsonData, err := json.Marshal(result)
				if err != nil {
					return fmt.Errorf("marshaling directory listing for %s: %w", filePath, err)
				}
				data = jsonData
				fileName = absPath
				mimeType = "directory"
			} else {
				data, err = os.ReadFile(filePath)
				if err != nil {
					return fmt.Errorf("reading file %s: %w", filePath, err)

View on GitHub (pinned to a4447c1563)

Solutions

  1. cd back to a valid directory (e.g. `cd ~` then `cd /path/to/project`) and rerun wsh ai.
  2. Restart the shell/terminal session if its cwd is gone.
  3. Pass an absolute file path — Abs on an absolute path skips Getwd, avoiding the failure.
  4. Recreate the deleted working directory before running the command.

Example fix

// before (cwd deleted)
$ rm -rf /tmp/build && wsh ai out.txt
// after
$ cd /home/user/project && wsh ai /home/user/project/out.txt
Defensive patterns

Strategy: validation

Validate before calling

if ! pwd >/dev/null 2>&1; then
  echo "current working directory is gone; cd to a valid directory first" >&2
  exit 1
fi

Try / catch

if err := runAI(args); err != nil {
    if strings.Contains(err.Error(), "getting absolute path") {
        // os.Getwd() failed: cd back to a valid directory or restart the shell, then retry
    }
    return err
}

Prevention

When it happens

Trigger: Running `wsh ai <file>` after the shell's cwd directory was removed or renamed (common when a build/temp dir is deleted out from under the process); getwd returning ENOENT/EACCES.

Common situations: Long-lived shells whose project directory was deleted/re-created (cwd now stale); working inside a removed tmpfs or container volume; scripts that `cd` into ephemeral dirs.

Related errors


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