Skip to content
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

::expect does not format. #156

Closed
luukvanderduim opened this issue Feb 17, 2024 · 1 comment
Closed

::expect does not format. #156

luukvanderduim opened this issue Feb 17, 2024 · 1 comment

Comments

@luukvanderduim
Copy link
Collaborator

In the code base we can find multiple occurrences of eg.:

let serde_val = serde_plain::to_string(&iface).expect("Unable to serialize {iface}");

or

let encoded = to_bytes(ctxt, &from_role).expect("Unable to encode {from_role}");

However, .expect() does not support inserting and formatting variables.
Also, inclusion of {err} is unnecessary because expect will append the error automatically:

See: playground example

And the std rust docs on Result::expect

"What were they thinking?"

Note the guidelines on the message itself in the link above.
The expect message should contain the reason or assumption why we expect Result::Ok().

Could we adopt this guidance, to help us or future developers, as when debugging it may help to learn about the rationale why we thought - at time of writing - this was okay.

Thoughts?

@TTWNO
Copy link
Member

TTWNO commented Feb 29, 2024

Interestingly, there is no clippy lint for this, but there is a proposal for one.

TTWNO added a commit that referenced this issue Feb 29, 2024
@TTWNO TTWNO closed this as completed in dbf81ac Mar 7, 2024
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

No branches or pull requests

2 participants