golangci/golangci-lint · error

get wd: %w

Error message

get wd: %w

What it means

GetBasePath returns this wrapped error when the relative path mode is RelativePathModeWd and Getwd() fails to determine the current working directory. The OS-level cause is preserved via %w. This is rare and usually means the process's working directory no longer exists or is inaccessible.

Source

Thrown at pkg/fsutils/basepath.go:59

		goMod, err := goenv.GetOne(ctx, goenv.GOMOD)
		if err != nil {
			return "", fmt.Errorf("get go.mod path: %w", err)
		}

		return filepath.Dir(goMod), nil

	case RelativePathModeGitRoot:
		root, err := gitRoot(ctx)
		if err != nil {
			return "", fmt.Errorf("get git root: %w", err)
		}

		return root, nil

	case RelativePathModeWd:
		wd, err := Getwd()
		if err != nil {
			return "", fmt.Errorf("get wd: %w", err)
		}

		return wd, nil

	default:
		return "", fmt.Errorf("unknown relative path mode: %s", mode)
	}
}

func gitRoot(ctx context.Context) (string, error) {
	cmd := exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel")
	out, err := cmd.Output()
	if err != nil {
		return "", err
	}

	return string(bytes.TrimSpace(out)), nil
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Re-create or cd back into a valid directory before running golangci-lint
  2. Check permissions on the working directory path (read/execute bits)
  3. Inspect the wrapped %w error for the exact OS cause (e.g. ENOENT, EACCES) and fix accordingly

Example fix

// shell before: run from a deleted dir
rm -rf /tmp/work && cd /tmp/work && golangci-lint run
// after
cd /existing/project && golangci-lint run
Defensive patterns

Strategy: try-catch

Validate before calling

if wd, err := os.Getwd(); err != nil {
  return fmt.Errorf("working directory unusable: %w", err)
}

Try / catch

basePath, err := fsutils.GetBasePath(ctx, mode)
if err != nil {
  if wd, wdErr := os.Getwd(); wdErr != nil {
    log.Fatalf("cwd unavailable: %v", wdErr) // re-enter a valid directory
  }
  return err
}

Prevention

When it happens

Trigger: Calling golangci-lint (with run.relative-path-mode: wd, or default flows calling GetBasePath) after the current directory has been deleted, or when permission/OS errors prevent os.Getwd from resolving it.

Common situations: CI jobs that delete the workspace while the linter runs; launching the process from a removed temp dir; broken symlinked working directories; permission problems on containers.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/0c4180a76e8f9fe4. Report an issue: GitHub.