substrate-docs icon indicating copy to clipboard operation
substrate-docs copied to clipboard

Avoid panic in examples

Open justinfrevert opened this issue 4 years ago • 1 comments

Content request

In some examples, we include panicking code. If examples like these are meant to be in the runtime, would they not risk panicking the runtime?

One example reported is here:

let updated_from_balance = sender_balance.checked_sub(value).ok_or(<Error<T>>::InsufficientFunds)?;
let updated_to_balance = receiver_balance.checked_add(value).expect("Entire supply fits in u64, qed");

An example fix might be to instead of using the expect, return an Error similar to the previous line.

Are you willing to help with this request?

Yes!

justinfrevert avatar Dec 27 '21 19:12 justinfrevert

@justinFrevert absolutely would be open to have you pick out these and fix :pray: :heart:

nuke-web3 avatar Jun 29 '22 22:06 nuke-web3