alibaba/open-code-review · error

resolve absolute path: %w

Error message

resolve absolute path: %w

What it means

resolveWorkingDir calls filepath.Abs on the user-supplied directory (or the resolved cwd) and wraps a failure with this message. filepath.Abs only fails when Getwd fails on a relative input, so this is rare and points at an unusable process cwd rather than a bad path string. The wrapped error identifies the cause.

Source

Thrown at cmd/opencodereview/shared.go:143

		GitRunner:  gitRunner,
		IsGitRepo:  isGit,
	}, nil
}

// resolveWorkingDir returns (absPath, isGitRepo, err). When requireGit is
// true, returns an error if the directory is not a git repo. When false,
// returns IsGitRepo=false instead of erroring (scan path uses this).
func resolveWorkingDir(input string, requireGit bool) (string, bool, error) {
	if input == "" {
		wd, err := os.Getwd()
		if err != nil {
			return "", false, fmt.Errorf("get working directory: %w", err)
		}
		input = wd
	}
	absPath, err := filepath.Abs(input)
	if err != nil {
		return "", false, fmt.Errorf("resolve absolute path: %w", err)
	}
	if _, statErr := os.Stat(absPath); statErr != nil {
		return "", false, fmt.Errorf("stat %s: %w", absPath, statErr)
	}
	out, err := runGitCmd(absPath, "rev-parse", "--git-dir")
	isGit := err == nil && len(out) > 0
	if !isGit && requireGit {
		return "", false, fmt.Errorf("%s is not a git repository", absPath)
	}
	// #287: git reports diff and `git show HEAD:<path>` paths relative to the
	// repository root, not the current directory. When `ocr review` runs from a
	// subdirectory of a monorepo, anchor RepoDir at the git top-level so those
	// root-relative paths resolve for both disk reads and git-show reads.
	// requireGit is true only for the review path; scan (requireGit=false) keeps
	// the CWD so its `git ls-files` walk stays scoped to the subdirectory.
	if isGit && requireGit {
		// runGitCmdStdout captures stdout only so git stderr notices can't
		// pollute the resolved path. --show-toplevel fails (or is empty) when

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Pass an absolute path to the command instead of a relative one
  2. Restore a valid working directory (cd to an existing path) before running
  3. If Getwd keeps failing, check for permission or mount problems on the cwd

Example fix

// before
ocr review --dir ../myrepo   # fails when cwd is gone
// after
ocr review --dir /abs/path/to/myrepo
Defensive patterns

Strategy: validation

Validate before calling

if !filepath.IsAbs(dir) {
	dir, err = filepath.Abs(dir)
	if err != nil {
		return err
	}
}

Try / catch

if err != nil {
	log.Printf("could not resolve path %q: %v", dir, err)
	return err
}

Prevention

When it happens

Trigger: ocr review/scan invoked with a relative --dir path while os.Getwd() fails (deleted cwd, permission loss), causing filepath.Abs(input) to return an error.

Common situations: Same as getwd failures: deleted current directory in CI, stale shell after workspace cleanup, containers with unmounted cwd.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/a917da9b3b5e405a. Report an issue: GitHub.