vault
vault copied to clipboard
To Figure: How to reduce the number of `match` statements without making the code error prone
To many nested match statements increases the code complexity for no reason
Also, To find the alternative of panic!() macro... It isn't the best way to give errors....
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?
Hi @Levi0804 , go ahead!
You could add thiserror or even anyhow to make stuff easy..