vault icon indicating copy to clipboard operation
vault copied to clipboard

To Figure: How to reduce the number of `match` statements without making the code error prone

Open shubhexists opened this issue 2 years ago • 3 comments

To many nested match statements increases the code complexity for no reason

shubhexists avatar Dec 15 '23 17:12 shubhexists

Also, To find the alternative of panic!() macro... It isn't the best way to give errors....

shubhexists avatar Dec 18 '23 22:12 shubhexists

Hey, A lot of nesting and match statements can be reduced by using error propagation

For example this: https://github.com/shubhexists/vault/blob/8249ae1e107da8db48b9f567058178f15fbd8b95/src/commands/commit.rs#L21-L25

here at line 22 could be rewritten as:

let current_branch = get_current_branch().map_err(|_| {
        io::Error::new(
            io::ErrorKind::InvalidInput,
            "Invalid Data found in .vault/init.yaml",
        )
})?;

Or we can also use something like thiserror ig.

Should I create a PR addressing this?

Levi0804 avatar Feb 28 '25 10:02 Levi0804

Hi @Levi0804 , go ahead! You could add thiserror or even anyhow to make stuff easy..

shubhexists avatar Feb 28 '25 12:02 shubhexists