mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
Add Diagnostic.try_amend()
to simplify error handling (#3701)
This commit is contained in:
parent
1bac206995
commit
dc4d7619ee
28 changed files with 192 additions and 300 deletions
|
@ -1,3 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use log::error;
|
||||
use rustpython_parser::ast::Location;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -45,6 +47,14 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn try_amend(&mut self, func: impl FnOnce() -> Result<Fix>) -> &mut Self {
|
||||
match func() {
|
||||
Ok(fix) => self.fix = Some(fix),
|
||||
Err(err) => error!("Failed to create fix: {}", err),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parent(&mut self, parent: Location) -> &mut Self {
|
||||
self.parent = Some(parent);
|
||||
self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue