-
Notifications
You must be signed in to change notification settings - Fork 296
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
Refuse use of unwrap in the codebase\; convert existing use of unwrap to expect/error results #2979
Conversation
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.
rg --count "unwrap" | awk -F: '{ print $2 ":" $1 }' | grep -v "/gen/" | grep -v "test" | sort -nr
56:crates/core/asset/src/balance/imbalance.rs
50:crates/wasm/src/view_server.rs
35:crates/core/component/shielded-pool/src/spend/proof.rs
28:crates/core/component/dex/src/batch_swap_output_data.rs
26:crates/bin/pcli/src/command/tx.rs
25:crates/core/component/stake/src/component.rs
24:crates/core/component/ibc/src/component/client.rs
21:crates/wasm/src/tx.rs
21:crates/core/asset/src/value.rs
20:crates/wasm/src/lib.rs
20:crates/core/component/governance/src/delegator_vote/proof.rs
20:crates/core/component/dex/src/swap_claim/proof.rs
19:crates/core/app/src/app/mod.rs
16:crates/misc/tct-visualize/src/bin/tct-visualize.rs
15:crates/core/num/src/fixpoint.rs
15:crates/bin/pd/src/info.rs
14:crates/view/src/storage/sct.rs
14:crates/core/component/ibc/src/component/transfer.rs
13:crates/view/src/storage.rs
13:crates/core/transaction/src/effect_hash.rs
12:crates/core/component/dex/src/lp/order.rs
11:crates/core/component/dex/src/component/dex.rs
10:crates/util/tendermint-proxy/src/tendermint_proxy.rs
10:crates/misc/tct-visualize/src/live/control.rs
10:crates/core/component/dex/src/lp/trading_function.rs
9:crates/storage/src/future.rs
9:crates/core/component/chain/src/genesis/app_state.rs
9:crates/core/asset/src/asset.rs
9:crates/core/app/src/action_handler/transaction.rs
8:crates/misc/tct-visualize/src/live/view.rs
8:crates/core/component/shielded-pool/src/nullifier_derivation.rs
8:crates/core/component/dex/src/swap/proof.rs
8:crates/core/component/dex/src/component/router/fill_route.rs
8:crates/bin/pd/src/info/specific.rs
8:crates/bin/pcli/src/command/query/dex.rs
7:pd/src/span_metrics.rs
7:crates/misc/measure/src/main.rs
7:crates/core/component/dex/src/component/router/params.rs
7:crates/bin/pcli/src/dex_utils/replicate/debug.rs
6:crates/view/src/service.rs
6:crates/crypto/tct/src/tree.rs
6:crates/crypto/tct/src/commitment.rs
6:crates/core/num/src/amount.rs
6:crates/bin/pd/src/main.rs
6:crates/bin/pcli/src/dex_utils/replicate/xyk.rs
5:crates/view/src/worker.rs
5:crates/crypto/tct/src/internal/frontier/top.rs
5:crates/crypto/tct/src/internal/frontier/node.rs
5:crates/crypto/proof-params/benches/delegator_vote.rs
5:crates/core/transaction/src/view/transaction_perspective.rs
5:crates/core/component/stake/src/penalty.rs
5:crates/core/component/shielded-pool/src/output/proof.rs
5:crates/core/component/shielded-pool/src/component/note_manager.rs
5:crates/bin/pcli/src/command/tx/replicate.rs
4:crates/view/src/sync.rs
4:crates/misc/tct-visualize/src/bin/tct-live-edit.rs
4:crates/crypto/proof-params/src/traits.rs
4:crates/crypto/proof-params/benches/swap_claim.rs
4:crates/core/transaction/src/plan/build.rs
4:crates/core/component/stake/src/uptime.rs
4:crates/core/component/stake/src/action_handler/validator_definition.rs
4:crates/core/component/ibc/src/component/msg_handler/connection_open_try.rs
4:crates/core/component/ibc/src/component/channel.rs
4:crates/core/component/dex/src/lp/nft.rs
4:crates/core/component/dex/src/component/position_manager.rs
4:crates/core/component/chain/src/lib.rs
4:crates/core/component/chain/src/component/app_hash.rs
4:crates/bin/pcli/src/main.rs
3:crates/storage/src/snapshot.rs
3:crates/storage/src/delta.rs
3:crates/narsil/narsil/src/bin/narsild.rs
3:crates/custody/src/soft_kms/config.rs
3:crates/crypto/tct/src/structure.rs
3:crates/crypto/tct/src/epoch.rs
3:crates/crypto/proof-params/build.rs
3:crates/core/component/stake/src/undelegate_claim/proof.rs
3:crates/core/component/stake/src/rate.rs
3:crates/core/component/shielded-pool/src/output/plan.rs
3:crates/core/component/shielded-pool/src/note.rs
3:crates/core/component/sct/src/component/view.rs
3:crates/core/component/ibc/src/component/packet.rs
3:crates/core/component/ibc/src/component/msg_handler/connection_open_ack.rs
3:crates/core/component/fee/src/fee.rs
3:crates/core/component/dex/src/swap/plaintext.rs
3:crates/core/component/dao/src/component/view.rs
3:crates/core/component/chain/src/component/view.rs
3:crates/core/app/src/governance/view.rs
3:crates/bin/pcli/src/command/view/staked.rs
3:crates/bin/pcli/src/command/utils.rs
3:crates/bin/pcli/src/command/debug.rs
2:crates/narsil/narsil/src/ledger/app.rs
2:crates/misc/tct-visualize/src/render/dot.rs
2:crates/crypto/tct/src/validate.rs
2:crates/crypto/tct/src/internal/frontier/tier.rs
2:crates/crypto/proof-params/benches/swap.rs
2:crates/crypto/proof-params/benches/spend.rs
2:crates/crypto/proof-params/benches/nullifier_derivation.rs
2:crates/crypto/decaf377-fmd/benches/fmd.rs
2:crates/core/transaction/src/memo.rs
2:crates/core/keys/src/keys/fvk/r1cs.rs
2:crates/core/keys/src/keys/fvk.rs
2:crates/core/component/shielded-pool/src/component/supply.rs
2:crates/core/component/shielded-pool/src/component/shielded_pool.rs
2:crates/core/component/ibc/src/component/msg_handler/create_client.rs
2:crates/core/component/ibc/src/component/msg_handler/connection_open_init.rs
2:crates/core/component/ibc/src/component/msg_handler/connection_open_confirm.rs
2:crates/core/component/ibc/src/component/msg_handler/channel_open_try.rs
2:crates/core/component/ibc/src/component/connection.rs
2:crates/core/component/dex/src/trading_pair.rs
2:crates/core/component/dex/src/component/swap_manager.rs
2:crates/core/component/dex/src/component/router/path.rs
2:crates/core/asset/src/balance.rs
2:crates/core/asset/src/asset/registry.rs
2:crates/bin/pd/src/events.rs
2:crates/bin/pcli/src/opt.rs
2:crates/bin/pcli/src/command/validator.rs
1:tools/proto-compiler/src/main.rs
1:tools/parameter-setup/src/main.rs
1:crates/wallet/src/plan.rs
1:crates/wallet/src/lib.rs
1:crates/view/src/lib.rs
1:crates/view/build.rs
1:crates/util/tower-trace/src/lib.rs
1:crates/util/tendermint-proxy/src/lib.rs
1:crates/storage/src/storage.rs
1:crates/storage/src/lib.rs
1:crates/proto/src/serializers/bech32str.rs
1:crates/narsil/narsil/src/lib.rs
1:crates/narsil/narsil/src/ledger/info.rs
1:crates/narsil/narsil/src/bin/narsilcli.rs
1:crates/narsil/narsil/build.rs
1:crates/misc/tct-visualize/src/live/view/earliest.rs
1:crates/misc/tct-visualize/src/lib.rs
1:crates/misc/measure/build.rs
1:crates/custody/src/lib.rs
1:crates/custody/build.rs
1:crates/crypto/tct/src/storage/deserialize.rs
1:crates/crypto/tct/src/lib.rs
1:crates/crypto/tct/src/internal/hash.rs
1:crates/crypto/tct/src/internal/complete/node.rs
1:crates/crypto/tct/src/block.rs
1:crates/crypto/proof-setup/src/log.rs
1:crates/crypto/proof-setup/src/lib.rs
1:crates/crypto/proof-params/src/lib.rs
1:crates/crypto/eddy/src/lib.rs
1:crates/crypto/decaf377-ka/src/lib.rs
1:crates/crypto/decaf377-fmd/src/lib.rs
1:crates/core/transaction/src/vote.rs
1:crates/core/transaction/src/plan/action.rs
1:crates/core/transaction/src/lib.rs
1:crates/core/transaction/src/auth_hash.rs
1:crates/core/transaction/src/action.rs
1:crates/core/num/src/lib.rs
1:crates/core/keys/src/lib.rs
1:crates/core/keys/src/keys/ivk.rs
1:crates/core/component/stake/src/unbonding_token.rs
1:crates/core/component/stake/src/lib.rs
1:crates/core/component/stake/src/delegation_token.rs
1:crates/core/component/shielded-pool/src/lib.rs
1:crates/core/component/shielded-pool/src/component/action_handler/spend.rs
1:crates/core/component/shielded-pool/src/component/action_handler/output.rs
1:crates/core/component/sct/src/lib.rs
1:crates/core/component/ibc/src/lib.rs
1:crates/core/component/ibc/src/component/msg_handler/update_client.rs
1:crates/core/component/ibc/src/component/msg_handler/channel_open_init.rs
1:crates/core/component/ibc/src/component/msg_handler/channel_open_confirm.rs
1:crates/core/component/ibc/src/component/msg_handler/channel_open_ack.rs
1:crates/core/component/ibc/src/component/msg_handler/channel_close_init.rs
1:crates/core/component/ibc/src/component/msg_handler/channel_close_confirm.rs
1:crates/core/component/governance/src/voting_receipt_token.rs
1:crates/core/component/governance/src/proposal_nft.rs
1:crates/core/component/governance/src/lib.rs
1:crates/core/component/fee/src/lib.rs
1:crates/core/component/distributions/src/lib.rs
1:crates/core/component/dex/src/lib.rs
1:crates/core/component/dex/src/component/router/path_search.rs
1:crates/core/component/dex/src/component/arb.rs
1:crates/core/component/dex/src/component/action_handler/swap_claim.rs
1:crates/core/component/dex/src/component/action_handler/swap.rs
1:crates/core/component/dao/src/lib.rs
1:crates/core/component/component/src/lib.rs
1:crates/core/component/compact-block/src/lib.rs
1:crates/core/component/compact-block/src/compact_block.rs
1:crates/core/asset/src/lib.rs
1:crates/core/app/src/lib.rs
1:crates/core/app/src/action_handler/transaction/stateless.rs
1:crates/core/app/src/action_handler/transaction/stateful.rs
1:crates/bin/pd/src/lib.rs
1:crates/bin/pd/build.rs
1:crates/bin/pclientd/src/main.rs
1:crates/bin/pclientd/src/lib.rs
1:crates/bin/pclientd/build.rs
1:crates/bin/pcli/src/network.rs
1:crates/bin/pcli/src/command/query/governance.rs
1:crates/bin/pcli/build.rs
display_regexes.push( | ||
displays | ||
.iter() | ||
.map(|d| Regex::new(d).expect("unable to parse display regex")) |
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.
The expect
argument should be a description of the invariant that's expected to be upheld, right? So this should be
.expect("display regex must be valid")
but why is that the case?
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.
The
expect
argument should be a description of the invariant that's expected to be upheld, right?
I am not sure. Our codebase is inconsistent on this and I've also heard it's better to write expect
messages like you would an anyhow::anyhow!("...")
error message due to the way they're printed in logs. It would be nice to pick one and stick with it.
but why is that the case?
Are you asking why the display regexes must be valid?
… to expect/error results
wip