nearcore icon indicating copy to clipboard operation
nearcore copied to clipboard

We should unwrap or expect on borsh `try_to_vec`

Open evgenykuzyakov opened this issue 4 years ago • 9 comments

Most of the code (all) that uses try_to_vec will never have an error from Borsh. Right now it's confusing which error a function can throw and some of them don't even need to return an Error at all.

If we replace try_to_vec()? with try_to_vec().expect("borsh") then the code going to be easier to handle. E.g.

https://github.com/nearprotocol/nearcore/blob/3ff069021a632807ec555d292503501c5e427ff5/chain/chain/src/validate.rs#L24

evgenykuzyakov avatar Nov 22 '19 19:11 evgenykuzyakov

@mikhailOK

evgenykuzyakov avatar Nov 22 '19 19:11 evgenykuzyakov

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 01 '21 12:07 stale[bot]

should we just implement something in borsh that unwraps the error?

bowenwang1996 avatar Jul 02 '21 22:07 bowenwang1996

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 30 '21 23:09 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 30 '21 22:12 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 07 '22 02:04 stale[bot]

Hi may I check if swapping propagation of error to expect statements still a good approach for this Issue?

codieboomboom avatar Apr 07 '22 10:04 codieboomboom

Hi may I check if swapping propagation of error to expect statements still a good approach for this Issue?

I think so. cc @matklad

bowenwang1996 avatar Apr 15 '22 17:04 bowenwang1996

@AnhTuDo1998 yes, we should generally add .expect to every try_to_vec. The devil is in details though -- we need to carefully check under which conditions this can actually panic (NaNs and collections longer than u32::MAX elements I think) and double-check that we can't hit such cases.

matklad avatar May 11 '22 13:05 matklad