From 9c84798f137deaf09d135c13e76aa586344b3e79 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 1 Sep 2023 10:33:52 +0530 Subject: [PATCH] Use the new error structure --- crates/ruff/src/linter.rs | 1 - crates/ruff_cli/src/commands/add_noqa.rs | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/ruff/src/linter.rs b/crates/ruff/src/linter.rs index 5a8812c8c9dc2..19612ab968da1 100644 --- a/crates/ruff/src/linter.rs +++ b/crates/ruff/src/linter.rs @@ -274,7 +274,6 @@ pub fn add_noqa_to_path( source_type: PySourceType, settings: &Settings, ) -> Result { - // Read the file from disk. let contents = source_kind.source_code(); // Tokenize once. diff --git a/crates/ruff_cli/src/commands/add_noqa.rs b/crates/ruff_cli/src/commands/add_noqa.rs index a7d12917712e2..8c59c5df76264 100644 --- a/crates/ruff_cli/src/commands/add_noqa.rs +++ b/crates/ruff_cli/src/commands/add_noqa.rs @@ -57,10 +57,13 @@ pub(crate) fn add_noqa( .and_then(|parent| package_roots.get(parent)) .and_then(|package| *package); let settings = resolver.resolve(path, pyproject_config); - let Ok(LintSource(source_kind)) = LintSource::try_from_path(path, source_type) else { - // TODO(dhruvmanila): Display the error to the user. - error!("Failed to extract source from {}", path.display()); - return None; + let LintSource(source_kind) = match LintSource::try_from_path(path, source_type) { + Ok(Some(source)) => source, + Ok(None) => return None, + Err(e) => { + error!("Failed to extract source from {}: {e}", path.display()); + return None; + } }; match add_noqa_to_path(path, package, &source_kind, source_type, settings) { Ok(count) => Some(count),