Prefer logging instead of panicking in Rust
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Install this rule for wispbit
Add this rule to wispbit and it will run when you open a pull request
Install this rule for Coderabbit
Copy the configuration below and add it to your repository as .coderabbit.yml
in your project root.
reviews:
path_instructions:
- path: "*.rs"
instructions: |
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
Install this rule for Greptile
Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
File Path Patterns:
Install this rule for GitHub Copilot
Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
File Path Patterns:
Install this rule for Graphite Diamond
Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
File Path Patterns:
Use with Cline
Copy the rule below and ask Cline to review your code using this rule
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
Use with OpenAI Codex
Copy the rule below and ask OpenAI Codex to review your code using this rule
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
Use with Cursor
Copy the rule below and ask Cursor to review your code using this rule
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
Use with Claude Code
Copy the rule below and ask Claude Code to review your code using this rule
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```
Install this rule for Windsurf
To set up rules for Windsurf Reviews, please see this documentation
Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking.
Bad:
```rust
let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap();
let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap();
```
Good:
```rust
let scroll_target_range = maybe!({
let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32;
let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32;
Some((top, bottom))
});
if scroll_target_range.is_none() {
log::error!("bug: failed to find blocks for scrolling to inline assist");
}
// Use a fallback value when the operation fails
let scroll_target_range = scroll_target_range.unwrap_or_else(|| {
// fallback calculation
});
```