Skip to content

Add github.com/cockroachdb/errors to hooks as alternative errors package#413

Merged
yuxincs merged 2 commits into
uber-go:mainfrom
Oneleet:ian/hooks-cockroachdb-errors
May 15, 2026
Merged

Add github.com/cockroachdb/errors to hooks as alternative errors package#413
yuxincs merged 2 commits into
uber-go:mainfrom
Oneleet:ian/hooks-cockroachdb-errors

Conversation

@ian-oneleet
Copy link
Copy Markdown
Contributor

https://github.com/cockroachdb/errors is a popular alternative to the stdlib errors package. It provides alternative versions of errors.New, fmt.Errorf (which it calls errors.Newf), and errors.Join, among other functions.

Nilaway currently flags more false positives for codebases that use cockroachdb/errors instead of stdlib errors, because the built-in special cases for stdlib errors don't carry over to cockroachdb/errors. This PR duplicates the special cases in hook/assume_return.go and hook/replace_conditional.go so that they work with cockroachdb/errors.

Code was produced with LLM assistance (Claude).

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 15, 2026

CLA assistant check
All committers have signed the CLA.

@ian-oneleet
Copy link
Copy Markdown
Contributor Author

@yuxincs friendly ping now that I've got CLA sign-off here 🙂

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.25%. Comparing base (ad240b1) to head (807c50b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #413   +/-   ##
=======================================
  Coverage   87.25%   87.25%           
=======================================
  Files          72       72           
  Lines        8306     8306           
=======================================
  Hits         7247     7247           
  Misses        867      867           
  Partials      192      192           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

Golden Test

Note

✅ NilAway errors reported on standard libraries are identical.

2567 errors on base branch (main, ad240b1)
2567 errors on test branch (5769900)

Comment thread hook/assume_return.go Outdated
{
kind: _func,
enclosingRegex: regexp.MustCompile(`^(stubs/)?github\.com/cockroachdb/errors$`),
funcNameRegex: regexp.MustCompile(`^Newf$`),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can probably merge this with the above with a (f)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged.

Comment on lines +21 to +25
// nilable(result 0)
func New(text string) error { return nil }

// nilable(errs[], result 0)
func Join(errs ...error) error { return nil }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These two actually return nonnil error per contract, could you update the stubs and annotations here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I've corrected this, but not positive I did it right. Would appreciate another look!

@yuxincs
Copy link
Copy Markdown
Contributor

yuxincs commented May 14, 2026

@ian-oneleet Hey, thanks for the contributions! I made two minor comments, could you take a look and see if they make sense? they should be simple fixes. After that I'll merge :)

@ian-oneleet ian-oneleet requested a review from yuxincs May 14, 2026 23:36
@yuxincs yuxincs merged commit c2da117 into uber-go:main May 15, 2026
9 checks passed
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.

3 participants