diff --git a/Cargo.lock b/Cargo.lock index 3c4cc3a5f..4fec049d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1368,7 +1368,6 @@ dependencies = [ "miette", "owo-colors", "textwrap", - "thiserror", "unicode-width", ] diff --git a/Cargo.toml b/Cargo.toml index 0737b7af4..6c9fc2926 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,7 +132,6 @@ serde = "1.0.199" serde_json = "1.0.116" syn = { version = "2.0.58", default-features = false } tempfile = "3.10.1" -thiserror = "1.0.59" tokio = "1" tower-lsp = "0.20.0" trybuild = "1.0.93" diff --git a/crates/oxc_diagnostics/Cargo.toml b/crates/oxc_diagnostics/Cargo.toml index 6fcdeac63..843bf0ec6 100644 --- a/crates/oxc_diagnostics/Cargo.toml +++ b/crates/oxc_diagnostics/Cargo.toml @@ -18,8 +18,7 @@ workspace = true doctest = false [dependencies] -thiserror = { workspace = true } -miette = { workspace = true } +miette = { workspace = true } unicode-width = { workspace = true } owo-colors = { workspace = true } diff --git a/crates/oxc_diagnostics/src/lib.rs b/crates/oxc_diagnostics/src/lib.rs index 990a6e43b..4ba9fba8c 100644 --- a/crates/oxc_diagnostics/src/lib.rs +++ b/crates/oxc_diagnostics/src/lib.rs @@ -1,5 +1,5 @@ //! Diagnostics Wrapper -//! Exports `thiserror` and `miette` +//! Exports `miette` mod graphic_reporter; mod graphical_theme; @@ -9,11 +9,9 @@ mod service; use std::{ fmt::{self, Display}, ops::Deref, - path::PathBuf, }; pub use miette; -pub use thiserror; pub use crate::{ graphic_reporter::GraphicalReportHandler, @@ -29,17 +27,6 @@ pub type Result = std::result::Result; use miette::{Diagnostic, SourceCode}; pub use miette::{LabeledSpan, NamedSource}; -use thiserror::Error; - -#[derive(Debug, Error, Diagnostic)] -#[error("File is too long to fit on the screen")] -#[diagnostic(help("{0:?} seems like a minified file"))] -pub struct MinifiedFileError(pub PathBuf); - -#[derive(Debug, Error, Diagnostic)] -#[error("Failed to open file {0:?} with error \"{1}\"")] -#[diagnostic(help("Failed to open file {0:?} with error \"{1}\""))] -pub struct FailedToOpenFileError(pub PathBuf, pub std::io::Error); #[derive(Debug, Clone)] pub struct OxcDiagnostic { diff --git a/crates/oxc_diagnostics/src/service.rs b/crates/oxc_diagnostics/src/service.rs index 6c83057fa..0974660fb 100644 --- a/crates/oxc_diagnostics/src/service.rs +++ b/crates/oxc_diagnostics/src/service.rs @@ -10,7 +10,7 @@ use crate::{ CheckstyleReporter, DiagnosticReporter, GithubReporter, GraphicalReporter, JsonReporter, UnixReporter, }, - Error, MinifiedFileError, Severity, + Error, OxcDiagnostic, Severity, }; pub type DiagnosticTuple = (PathBuf, Vec); @@ -139,7 +139,10 @@ impl DiagnosticService { if let Some(mut err_str) = self.reporter.render_error(diagnostic) { // Skip large output and print only once if err_str.lines().any(|line| line.len() >= 400) { - let minified_diagnostic = Error::new(MinifiedFileError(path.clone())); + let minified_diagnostic = Error::new( + OxcDiagnostic::warning("File is too long to fit on the screen") + .with_help(format!("{path:?} seems like a minified file")), + ); err_str = format!("{minified_diagnostic:?}"); output = err_str; break; diff --git a/crates/oxc_linter/src/service.rs b/crates/oxc_linter/src/service.rs index 9c66acf52..986ce55f2 100644 --- a/crates/oxc_linter/src/service.rs +++ b/crates/oxc_linter/src/service.rs @@ -12,7 +12,7 @@ use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; use rustc_hash::FxHashSet; use oxc_allocator::Allocator; -use oxc_diagnostics::{DiagnosticSender, DiagnosticService, Error, FailedToOpenFileError}; +use oxc_diagnostics::{DiagnosticSender, DiagnosticService, Error, OxcDiagnostic}; use oxc_parser::Parser; use oxc_resolver::Resolver; use oxc_semantic::{ModuleRecord, SemanticBuilder}; @@ -177,8 +177,11 @@ impl Runtime { return None; } let source_type = source_type.unwrap_or_default(); - let file_result = fs::read_to_string(path) - .map_err(|e| Error::new(FailedToOpenFileError(path.to_path_buf(), e))); + let file_result = fs::read_to_string(path).map_err(|e| { + Error::new(OxcDiagnostic::error(format!( + "Failed to open file {path:?} with error \"{e}\"" + ))) + }); Some(match file_result { Ok(source_text) => Ok((source_type, source_text)), Err(e) => Err(e),