Crates.io | panic-free-analyzer |
lib.rs | panic-free-analyzer |
version | 0.1.0 |
source | src |
created_at | 2024-01-10 02:18:49.239189 |
updated_at | 2024-01-10 02:18:49.239189 |
description | an audit tool to scan your crate or workspace searching for potential panic points in your codebase |
homepage | |
repository | https://github.com/YassinEldeeb/panic_free_analyzer |
max_upload_size | |
id | 1094839 |
size | 13,301 |
Rust Panic Free Analyzer is an audit tool designed to scan your Rust crate or workspace. Its primary function is to identify potential panic points in your codebase, leading you in developing binaries and libraries that are as close to "Panic Free" as possible.
âšī¸ As of now, it only currently searches the crates that you develop, and not the dependencies of your crates.
The tool searches for usage of several key patterns in Rust code that are often associated with panic points. These include:
panic!
: Direct calls to the panic!
macro, which causes the program to terminate immediately and provide an error message.
unwrap
: Calls to the .unwrap()
method, often used on Option
or Result
types, which will cause a panic if the value is None
or Err
.
expect
: Similar to unwrap
, but allows specifying a custom error message.
Array Indexing
: Direct indexing into arrays (e.g., arr[index]) without bounds checking, which can panic if the index is out of bounds. (A safer indexing method is .get()
)
unreachable!
: Indicates code that should never be reached; panics if executed.
todo!
and unimplemented!
: Macros indicating incomplete or unimplemented code, which will panic if reached.
To start using it, you need to install it first.
cargo install panic-free-analyzer
After installation, you can run the analyzer on your crate or entire workspace. Use the following command:
cargo panic-analyzer
If you wish to exclude specific crates from your workspace during the analysis, set the `IGNORED_CRATES`` environment variable. Pass the names of the crates you want to exclude, separated by commas:
IGNORED_CRATES=tests,benches cargo panic-analyzer
Below is an example of an audit result generated by the Rust Panic Free Analyzer:
vrl
đ Total Usages: 37
expect
usages: 1unwrap
usages: 32panic
usages: 1array_index
usages: 3jwt_auth
đ Total Usages: 31
unwrap
usages: 29array_index
usages: 2config
đ Total Usages: 14
panic
usages: 3expect
usages: 3unwrap
usages: 8common
đ Total Expected Usages: 1
panic!("Exited process!")
./libs/common/src/lib.rs:18