-
Notifications
You must be signed in to change notification settings - Fork 441
chore(gnovm): optimize err msg #4936
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
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| err := checkAssignableTo(x, xt, dt) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt)) | ||
| } |
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.
Should we wrap the error in the panic message ?
We may loose some information isn't ? Looks fine to me since the message indicate the position and show both types so it's enough to understand where & what is the problem.
Also in preprocess.go we show this message, should we have make the panic messages similar for consistence ?
if checkAssignableTo(n, tt, st) != nil {
panic(
fmt.Sprintf(
"cannot use %v (value of type %s) as %s value in assignment",
valueExpr.String(),
tt.String(),
st.String(),
),
)
}Also what about editing directly assertAssignableTo to print your improved message instead doing it specifically at one place.
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.
Should we wrap the error in the panic message ?
I think the low-level message is useful for debugging, but not for end users. We should log it instead of returning. :51625b8
Also in preprocess.go we show this message, should we have make the panic messages similar for consistence ?
it looks the correct, see gnovm/tests/files/assign33.gno.
Also what about editing directly assertAssignableTo to print your improved message instead doing it specifically at one place.
for me it still make sense that it provides lower-level infos.
| } | ||
|
|
||
| func assertAssignableTo(n Node, xt, dt Type) { | ||
| func mustAssignableTo(n Node, xt, dt Type) { |
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.
nit: but why must overt assert
IMO, i use must when i expect something in return like: "mustGetEntity" and assert when i don't expect a return but it's how i see it, just is there a reason behind this change ?
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.
for me, must is more of a convention from Go stdlibs, e.g.
regexp.MustCompile(...) (Panics if regex is invalid)
template.Must(...) (Panics if template parsing fails)while assert is always used in unit test, e.g. testify/assert.
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.
LGTM
| err := checkAssignableTo(x, xt, dt) | ||
| if err != nil { | ||
| if debug { | ||
| debug.Printf("checkAssignableTo fail: %v\n", err) | ||
| } | ||
| panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt)) | ||
| } |
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.
log low-level error and return user friendly info, which is more in line with Go.
thehowl
left a comment
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.
looks like an improvement, but i would avoid re-writing the full expression in the error
| if debug { | ||
| debug.Printf("checkAssignableTo fail: %v\n", err) | ||
| } | ||
| panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt)) |
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.
security-wise, we should maybe avoid panicking with the whole expression, as it might be very deep. what about making the error "types %v and %v are not comparable"?
this PR improves the error message for comparison mismatch that mentioned in #4911.