stability: wrap errors with %w instead of %v #1

Open
opened 2026-05-23 18:30:00 +00:00 by Klaus · 0 comments
Owner

Problem

Most fmt.Errorf calls across operation/ wrap errors with %v, which converts them to strings and loses the underlying error type. Callers can't use errors.Is / errors.As to distinguish API failures (404 vs 500), context cancellations, or SDK error types.

Affected files (non-exhaustive):

  • operation/milestone/milestone.go
  • operation/repo/branch.go, operation/repo/release.go, operation/repo/commit.go, operation/repo/file.go, operation/repo/repo.go, operation/repo/tag.go, operation/repo/tree.go
  • operation/label/label.go
  • operation/pull/pull.go
  • operation/wiki/wiki.go
  • operation/issue/issue.go
  • operation/search/search.go
  • operation/timetracking/timetracking.go
  • operation/user/user.go
  • operation/notification/notification.go
  • operation/packages/packages.go
  • pkg/to/to.go

operation/actions/runs.go already does this correctly — good reference.

Suggested direction

Sweep fmt.Errorf(".*%v", err)fmt.Errorf(".*%w", err). Add a golangci-lint rule (errorlint) to keep new code consistent.

## Problem Most `fmt.Errorf` calls across `operation/` wrap errors with `%v`, which converts them to strings and loses the underlying error type. Callers can't use `errors.Is` / `errors.As` to distinguish API failures (404 vs 500), context cancellations, or SDK error types. Affected files (non-exhaustive): - `operation/milestone/milestone.go` - `operation/repo/branch.go`, `operation/repo/release.go`, `operation/repo/commit.go`, `operation/repo/file.go`, `operation/repo/repo.go`, `operation/repo/tag.go`, `operation/repo/tree.go` - `operation/label/label.go` - `operation/pull/pull.go` - `operation/wiki/wiki.go` - `operation/issue/issue.go` - `operation/search/search.go` - `operation/timetracking/timetracking.go` - `operation/user/user.go` - `operation/notification/notification.go` - `operation/packages/packages.go` - `pkg/to/to.go` `operation/actions/runs.go` already does this correctly — good reference. ## Suggested direction Sweep `fmt.Errorf(".*%v", err)` → `fmt.Errorf(".*%w", err)`. Add a `golangci-lint` rule (`errorlint`) to keep new code consistent.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Klaus/gitea-mcp#1