-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add modeling for errors.As
in the generalized hook framework
#281
Conversation
a6605e3
to
5bba008
Compare
ad71408
to
261833f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #281 +/- ##
==========================================
+ Coverage 87.63% 87.66% +0.02%
==========================================
Files 65 66 +1
Lines 7916 7943 +27
==========================================
+ Hits 6937 6963 +26
Misses 798 798
- Partials 181 182 +1 ☔ View full report in Codecov by Sentry. |
Golden TestWarning ❌ NilAway errors reported on stdlib are different 📉. 3271 errors on base branch (main, 3c8ea06) Diffs- /opt/hostedtoolcache/go/1.22.7/x64/src/crypto/tls/handshake_server_test.go:373:32: Potential nil panic detected. Observed nil flow from source to dereference point:
- - tls/handshake_server_test.go:373:32: unassigned variable `opErr` accessed field `Err`
- /opt/hostedtoolcache/go/1.22.7/x64/src/errors/example_test.go:93:35: Potential nil panic detected. Observed nil flow from source to dereference point:
- - errors/example_test.go:93:35: unassigned variable `pathError` accessed field `Path`
- /opt/hostedtoolcache/go/1.22.7/x64/src/go/types/api_test.go:2516:6: Potential nil panic detected. Observed nil flow from source to dereference point:
- - types/api_test.go:2516:6: unassigned variable `argErr` accessed field `Index`
-
- (Same nil source could also cause potential nil panic(s) at 1 other place(s): "types/api_test.go:2517:85".)
- /opt/hostedtoolcache/go/1.22.7/x64/src/io/fs/readdir_test.go:101:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - fs/readdir_test.go:101:9: unassigned variable `perr` accessed field `Path`
- /opt/hostedtoolcache/go/1.22.7/x64/src/net/dnsclient_unix.go:859:33: Potential nil panic detected. Observed nil flow from source to dereference point:
- - net/dnsclient_unix.go:859:33: unassigned variable `dnsErr` accessed field `IsNotFound`
- /opt/hostedtoolcache/go/1.22.7/x64/src/net/dnsclient_unix_test.go:2677:34: Potential nil panic detected. Observed nil flow from source to dereference point:
- - net/dnsclient_unix_test.go:2677:34: unassigned variable `dnsErr` accessed field `Err`
- /opt/hostedtoolcache/go/1.22.7/x64/src/net/lookup_test.go:1435:8: Potential nil panic detected. Observed nil flow from source to dereference point:
- - net/lookup_test.go:1435:8: unassigned variable `dnsErr` accessed field `IsNotFound`
-
- (Same nil source could also cause potential nil panic(s) at 1 other place(s): "net/lookup_test.go:1440:7".)
- /opt/hostedtoolcache/go/1.22.7/x64/src/os/os_test.go:852:29: Potential nil panic detected. Observed nil flow from source to dereference point:
- - os/os_test.go:852:29: unassigned variable `pe` accessed field `Path` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Like the support for errors.As()
👍
20f09c3
to
f9f73a6
Compare
2f0f44b
to
fca4e01
Compare
This PR introduces a new hook point in the CFG preprocessing logic to replace conditionals with equivalent expressions (along with a few simple renames and comment additions for better readability).
With the new hook, we are introducing modeling for
errors.As(err, &target)
since it is equivalent toerrors.As(err, &target) && target != nil
. This makes the implication explicit such that NilAway is able to understand it during the analysis.Note that technically
target
can still be nil even iferrors.As(err, &target)
is true. For example, if err is a typed nil (e.g.,var err *exec.ExitError
), thenerrors.As
would actually find a match, buttarget
would be set to the typed nil value, resulting in anil
target. However, in practice this should rarely happen such that even the official documentation assumes the target is non-nil after such check [1]. So here we make this assumption as well.[1] https://pkg.go.dev/errors#As
Fixes #95