feat: re-export stdlib errors for drop-in replacement#30
Conversation
Re-export Is, As, Unwrap, Join, and ErrUnsupported from the standard library so callers can use github.com/go-coldbrew/errors as their sole errors import without needing a separate "errors" import for stdlib functions. Also adds: - AsType generic re-export (behind go1.26 build tag) - Standalone Cause(err) function that walks the Unwrap chain - Updated package documentation and examples
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 12 minutes and 31 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds standard library Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~18 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a “drop-in replacement” surface to github.com/go-coldbrew/errors by exposing key standard library errors APIs directly from this package, plus a new standalone Cause(err error) helper, and updates docs/examples accordingly.
Changes:
- Added stdlib-style wrappers for
Is,As,Unwrap,Join, plusErrUnsupportedre-export. - Added standalone
Cause(err error) errorto walk the single-errorUnwrap()chain to the root. - Updated package docs/README/examples and extended tests to cover the new API surface (including a Go 1.26–gated
AsType).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| stdlib.go | Introduces stdlib errors API wrappers and standalone Cause. |
| stdlib_go126.go | Adds Go-version-gated generic AsType wrapper. |
| doc.go | Updates package-level documentation to describe drop-in usage. |
| README.md | Regenerates README to document the new API surface and examples. |
| example_test.go | Adds/updates examples to demonstrate the drop-in replacement pattern. |
| errors_test.go | Adds tests for Is/As/Unwrap/Join/ErrUnsupported/standalone Cause. |
| notifier/README.md | Regenerated doc links to match updated line numbers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
stdlib_go126.go (1)
1-14: Add CI coverage for the go1.26-gated API path.
AsTypeis compiled only under//go:build go1.26; the CI runs Go 1.25.9 (from go.mod), so this code path is never tested and can silently rot. Consider adding a Go 1.26 job to the CI matrix.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@stdlib_go126.go` around lines 1 - 14, The CI lacks a job that builds/tests the go1.26-gated API (AsType in stdlib_go126.go), so that file is never exercised; update the CI matrix to add a Go 1.26 build/test job (or upgrade the existing Go version) that runs the test suite and module verification against go1.26 so the //go:build go1.26 path (AsType) is compiled and covered in CI. Ensure the job uses Go 1.26 toolchain and runs the same test/lint steps as other matrix entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@doc.go`:
- Around line 5-7: Replace the overbroad sentence claiming "All functions from
the standard library errors package are re-exported" with a precise statement
that lists the actual helpers re-exported (Is, As, Unwrap, Join, and
ErrUnsupported) and add a short note that some stdlib APIs are version-gated and
not re-exported; update the doc.go text around the current sentence to reflect
this narrower, accurate wording.
In `@errors_test.go`:
- Around line 270-273: Update the misleading test comment to reflect that the
test constructs a multi-error via stderrors.Join rather than an fmt.Errorf
chain: change the line "// Works on stdlib fmt.Errorf chains" to something like
"// Works on stdlib multi-error created with stderrors.Join" (referencing
import_io_err, fmtWrapped and stderrors.Join in the test) so the comment matches
the behavior being validated by Cause.
In `@README.md`:
- Around line 20-55: The generated README triggers markdownlint MD040/MD001
because of unlabeled fenced code blocks and non-sequential heading levels;
update the gomarkdoc template (the generator that emits the README) to add
language labels to all fenced code blocks (e.g., ```go or ```text) and ensure
headings follow a natural sequence (or explicitly emit markdownlint disable
directives for generated sections); alternatively, adjust the repo's
markdownlint config to exclude generated files or disable MD040/MD001 for the
generated README so the generated output no longer triggers those warnings.
In `@stdlib.go`:
- Around line 63-70: The Cause function can loop forever on cyclic Unwrap
chains; add a defensive bounded traversal: define a small constant (e.g.,
maxUnwraps) and count iterations inside Cause while calling
stderrors.Unwrap(err), returning the current err if the count exceeds the bound;
update Cause (and any local variable names like unwrapped) to break out and
return the last-seen error when the bound is hit to prevent infinite loops.
---
Nitpick comments:
In `@stdlib_go126.go`:
- Around line 1-14: The CI lacks a job that builds/tests the go1.26-gated API
(AsType in stdlib_go126.go), so that file is never exercised; update the CI
matrix to add a Go 1.26 build/test job (or upgrade the existing Go version) that
runs the test suite and module verification against go1.26 so the //go:build
go1.26 path (AsType) is compiled and covered in CI. Ensure the job uses Go 1.26
toolchain and runs the same test/lint steps as other matrix entries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 55a6a38d-55cf-4a12-b24c-8e7dc11c240a
📒 Files selected for processing (7)
README.mddoc.goerrors_test.goexample_test.gonotifier/README.mdstdlib.gostdlib_go126.go
- Add bounded traversal (max 1024) to Cause to guard against cyclic Unwrap chains - Fix doc comments to avoid ambiguous [errors.X] self-links - Reword "all functions" claim to accurately describe re-exported subset - Fix misleading test comment (Join multi-error, not fmt.Errorf chain) - Regenerate README
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Is,As,Unwrap,Join, andErrUnsupportedfrom the standard libraryerrorspackage so callers can usegithub.com/go-coldbrew/errorsas their sole errors importAsTypegeneric re-export behind a//go:build go1.26build tagCause(err error) errorfunction that walks theUnwrapchain to find root cause (works on any error, not justErrorExt)Test plan
make test— all existing + 7 new tests pass (TestIs, TestAs, TestUnwrap, TestJoin, TestErrUnsupported, TestCauseStandalone)make lint— 0 issuesmake doc— README regenerated with new API surfaceinterceptorsto remove dualstdError "errors"importSummary by CodeRabbit
Documentation
New Features