Skip to content

feat: re-export stdlib errors for drop-in replacement#30

Merged
ankurs merged 2 commits intomainfrom
feat/stdlib-drop-in-replacement
Apr 11, 2026
Merged

feat: re-export stdlib errors for drop-in replacement#30
ankurs merged 2 commits intomainfrom
feat/stdlib-drop-in-replacement

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 11, 2026

Summary

  • Re-export Is, As, Unwrap, Join, and ErrUnsupported from the standard library errors package so callers can use github.com/go-coldbrew/errors as their sole errors import
  • Add AsType generic re-export behind a //go:build go1.26 build tag
  • Add standalone Cause(err error) error function that walks the Unwrap chain to find root cause (works on any error, not just ErrorExt)
  • Update package documentation and examples to demonstrate the drop-in replacement pattern

Test plan

  • make test — all existing + 7 new tests pass (TestIs, TestAs, TestUnwrap, TestJoin, TestErrUnsupported, TestCauseStandalone)
  • make lint — 0 issues
  • make doc — README regenerated with new API surface
  • Verify CI passes
  • After merge: update interceptors to remove dual stdError "errors" import

Summary by CodeRabbit

  • Documentation

    • Enhanced README with comprehensive function documentation and usage examples
    • Updated package documentation describing standard library compatibility
  • New Features

    • Re-exported standard error functions (Is, As, Unwrap, Join, ErrUnsupported) for drop-in compatibility
    • Added Cause function for root error extraction
    • Added AsType generic function for Go 1.26+

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
Copilot AI review requested due to automatic review settings April 11, 2026 04:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

Warning

Rate limit exceeded

@ankurs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 31 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 74e73b65-b79e-4d97-9cbd-f6c9d5985777

📥 Commits

Reviewing files that changed from the base of the PR and between 4107638 and a4a9db4.

📒 Files selected for processing (5)
  • README.md
  • doc.go
  • errors_test.go
  • stdlib.go
  • stdlib_go126.go
📝 Walkthrough

Walkthrough

This PR adds standard library errors package re-exports to enable the ColdBrew errors package as a drop-in replacement. Introduces re-exported functions (Is, As, Unwrap, Join, ErrUnsupported) and a new Cause function for root-error extraction, along with comprehensive test coverage and usage examples. Go 1.26+ compatibility via generic AsType function.

Changes

Cohort / File(s) Summary
Standard Library Re-exports
stdlib.go, stdlib_go126.go
Added wrapper functions delegating to standard library equivalents (Is, As, Unwrap, Join, ErrUnsupported). New Cause function walks the error chain to extract the root cause. Generic AsType added for Go 1.26+.
Test Coverage
errors_test.go
Added comprehensive test coverage for Is, As, Unwrap, Join, ErrUnsupported, and Cause functions with edge cases. Updated existing tests to use package-level Is instead of stdlib variant. Minor refactoring of loop variable assignment.
Usage Examples
example_test.go
Removed stderrors import alias and added five example functions demonstrating Is, As, Join, Unwrap, and Cause behaviors. Updated ExampleWrap_errorsIs to use re-exported errors.Is.
Documentation
doc.go, README.md, notifier/README.md
Updated package documentation and README to describe the package as a drop-in replacement for Go's errors package, documenting all re-exports and the new Cause function with usage guidance. Updated documentation hyperlink line numbers in notifier README.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~18 minutes

Possibly related PRs

Poem

🐰 With gentle hops, we bridge the gap,
Stdlib's strengths now in our lap,
One import rings, no need to split,
Standard errors? We commit!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: re-exporting stdlib errors functions to enable drop-in replacement usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/stdlib-drop-in-replacement

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, plus ErrUnsupported re-export.
  • Added standalone Cause(err error) error to walk the single-error Unwrap() 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
stdlib_go126.go (1)

1-14: Add CI coverage for the go1.26-gated API path.

AsType is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 25cb915 and 4107638.

📒 Files selected for processing (7)
  • README.md
  • doc.go
  • errors_test.go
  • example_test.go
  • notifier/README.md
  • stdlib.go
  • stdlib_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
@ankurs ankurs requested a review from Copilot April 11, 2026 05:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ankurs ankurs merged commit 06ce8d6 into main Apr 11, 2026
11 checks passed
@ankurs ankurs deleted the feat/stdlib-drop-in-replacement branch April 11, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants