Previously in this series, we finished our CLI application in rust using CLAP. In this final post of this series, we will cover error handling and fixing unnecessary panics in applications.
In Rust, we group errors into two major categories, also rust doesn't have exceptions.
- Recoverable Errors - Result
- Unrecoverable Errors - panic!
We will refactor our code in such a way that only Unrecoverable errors should panic the application execution rest are handled by the recoverable errors.
After handling all the errors and panicking whenever necessary our code looks something like this.
In this series, we have covered how to create a rust cli application, how to add commands, and how to add flags to commands. In addition to that, we have covered basic cryptography techniques like encryption, decryption and generating keystores or secrets. Clap is a wonderful library which helps us in writing cli applications in rust. We have successfully completed building our cli application in this series. If any of the content in this series is unclear please leave a comment and I will update the post to make it clearer.