Add modeling for errors.As in the generalized hook framework#281
Merged
Add modeling for errors.As in the generalized hook framework#281
errors.As in the generalized hook framework#281Conversation
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` |
sonalmahajan15
approved these changes
Sep 30, 2024
Contributor
sonalmahajan15
left a comment
There was a problem hiding this comment.
Nice! Like the support for errors.As() 👍
20f09c3 to
f9f73a6
Compare
2f0f44b to
fca4e01
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
targetcan 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.Aswould actually find a match, buttargetwould be set to the typed nil value, resulting in aniltarget. 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