What it does
I want to demonstrate below, what I'd like a potential linter to prevent. This should be an optional linter:
if let Ok(res) = some_call() {
//Do something with res
} else {
error!("Something went wrong, but I don't know what");
}
vs
match some_call() {
Ok(res) => // Do something with res,
Err(e) => {
error!("Something went wrong: {}", e);
}
}
In the former example, the Err variant is ignored, and you're losing context. And for more complex error types, you might be able to recover depending on the type of error.
In the latter, it's enforing that something is done with the Err variant and isn't ignored.
I would love to have a linter that warns (or fails) if the Err variant is ignored.
Advantage
- For people who want to use it, it can ensure accurate and detailed logging
- Allows for the ability to recover from an error, if you know what's happened
- Context is not lost
Drawbacks
- Not everyone may want such a lint check, so it should be opt in
Example
if let Ok(res) = some_call() {
//Do something with res
} else {
error!("Something went wrong, but I don't know what");
}
Could be written as:
match some_call() {
Ok(res) => // Do something with res,
Err(e) => {
error!("Something went wrong: {}", e);
}
}
Comparison with existing lints
I don't know if an existing linter like this or similar to this exists. The closest one I can think of is this:
Additional Context
No response
What it does
I want to demonstrate below, what I'd like a potential linter to prevent. This should be an optional linter:
vs
In the former example, the Err variant is ignored, and you're losing context. And for more complex error types, you might be able to recover depending on the type of error.
In the latter, it's enforing that something is done with the Err variant and isn't ignored.
I would love to have a linter that warns (or fails) if the Err variant is ignored.
Advantage
Drawbacks
Example
Could be written as:
Comparison with existing lints
I don't know if an existing linter like this or similar to this exists. The closest one I can think of is this:
Additional Context
No response