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

Feat:recovereable error functions in scope src/cli #1106

Conversation

vuvoth
Copy link
Contributor

@vuvoth vuvoth commented Feb 8, 2024

Motivation

More context

If this PR look good, I will continue update for another scope like @arthurpaulino suggest in this comment

Thank you for all review and suggestions!

@vuvoth vuvoth changed the title Feat:recovereable error in function [WIP] Feat:recovereable error in function Feb 8, 2024
@arthurpaulino
Copy link
Member

Hi, just to offer some directions in terms of prioritization for a first round of work (this doesn't need to be resolved on a single PR).

These are the places that contain the most important parts of the codebase, as far as I can tell:

  • src/cli
  • src/lem
  • src/proof

So starting on those is a better first step 👍🏼

Copy link
Member

@wwared wwared left a comment

Choose a reason for hiding this comment

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

Echoing what @arthurpaulino said, it'll probably be easier if this is done over multiple PRs since there are many places in the codebase that show up in the cargo clippy output.

I'm adding a couple of comments below to try and clarify some points, let me know if you have any questions!

Comment on lines 119 to 120
let a: [u8; 2] = x.clone().try_into().unwrap();
let x_clone = x.clone();
let a: [u8; 2] = [x_clone[0], x_clone[1]];
Copy link
Member

Choose a reason for hiding this comment

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

This change doesn't modify how the code works: if x_clone[0] or x_clone[1] is out of bounds, there will be a runtime panic.
An alternative to prevent the panic is to add a match block to handle the result of x.clone().try_into(), and return an Err if it is not Ok. (Similar to the code inside deserialize_u32)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I misunderstood the "match guards" in Rust.
I will fix it soon!

Comment on lines 151 to 152
// This error can't happend?
Err(_) => Err(SerdeError::Type(
Copy link
Member

@wwared wwared Feb 9, 2024

Choose a reason for hiding this comment

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

This error could still happen if x.len() is not 8, in which case the .try_into() would fail to convert it into a [u8; 8].

This is because in your change you removed the if x.len() == 8 condition in the match arm (before the =>, see the match guards section of the rust reference for a thorough explanation).

Previously, in both this function (and the deserialize_u32 function that has a similar pattern), it would never run the x.clone().try_into().unwrap(); line unless the if x.len() == 8 condition passed. This means that even though there was an .unwrap() here, it would never panic in practice, since the condition guarantees that the .try_into() should always succeed.

cargo clippy has no way of checking the above conditions, and that's why it listed this location among the rest. (Unfortunately, there's no easy way of checking this besides looking at each .unwrap() call in a case-by-case basis.)

@vuvoth
Copy link
Contributor Author

vuvoth commented Feb 10, 2024

Thank @arthurpaulino and @wwared for useful suggestions. I will check it after Lunar New Year.
Happy Year of the Dragon 🐉! 🥰🥰🥰

@vuvoth vuvoth force-pushed the feat/vu/handle-recovereable-error-in-function branch from d55306a to 1049fbb Compare February 13, 2024 16:55
@vuvoth vuvoth changed the title [WIP] Feat:recovereable error in function [WIP] Feat:recovereable error functions inside scope src/cli Feb 13, 2024
@vuvoth vuvoth changed the title [WIP] Feat:recovereable error functions inside scope src/cli [WIP] Feat:recovereable error functions Feb 13, 2024
@vuvoth vuvoth changed the title [WIP] Feat:recovereable error functions [WIP] Feat:recovereable error functions in scope src/cli Feb 13, 2024
@vuvoth vuvoth requested a review from wwared February 13, 2024 17:02
@vuvoth vuvoth changed the title [WIP] Feat:recovereable error functions in scope src/cli Feat:recovereable error functions in scope src/cli Feb 13, 2024
Copy link
Member

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

A stylistic remark for the incoming changes of this kind.

I'd usually state this change as a nitpick, but since you're going to make several changes of this kind, it's worth to start with a style that better suits lurk-rs from the beginning.

Also, thank you!
If this is all for what you found in src/cli, it's fine for an initial PR. The other folders can be covered on other PRs

src/cli/repl/meta_cmd.rs Outdated Show resolved Hide resolved
@vuvoth
Copy link
Contributor Author

vuvoth commented Feb 14, 2024

Thank you for your comments, @arthurpaulino. It's would be better if I followed the code style you recommend!

@vuvoth vuvoth force-pushed the feat/vu/handle-recovereable-error-in-function branch from 60a5f2a to d2c0e5f Compare February 14, 2024 03:34
@arthurpaulino
Copy link
Member

The current changes look good. I will wait until you set the PR as ready for review before I do another check and run the tests

@vuvoth vuvoth marked this pull request as ready for review February 14, 2024 11:20
@vuvoth vuvoth requested a review from a team as a code owner February 14, 2024 11:20
Copy link
Member

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

Thanks!

@arthurpaulino arthurpaulino added this pull request to the merge queue Feb 14, 2024
Merged via the queue into argumentcomputer:main with commit ffb4071 Feb 14, 2024
11 of 21 checks passed
arthurpaulino added a commit that referenced this pull request Feb 15, 2024
* Create a (new) InterpretationData to hold interpretation data on MultiFrame
* Remove some unwraps/expects because interpretation data is no longer spread
  across multiple holders
* [unrelated] Undo a change from #1106 where a panic was the desired behavior
github-merge-queue bot pushed a commit that referenced this pull request Feb 15, 2024
* Create a (new) InterpretationData to hold interpretation data on MultiFrame
* Remove some unwraps/expects because interpretation data is no longer spread
  across multiple holders
* [unrelated] Undo a change from #1106 where a panic was the desired behavior
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