mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(diagnostics): remove thiserror
This commit is contained in:
parent
f7a37739c8
commit
551632a348
6 changed files with 13 additions and 23 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1368,7 +1368,6 @@ dependencies = [
|
|||
"miette",
|
||||
"owo-colors",
|
||||
"textwrap",
|
||||
"thiserror",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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<T> = std::result::Result<T, OxcDiagnostic>;
|
|||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
CheckstyleReporter, DiagnosticReporter, GithubReporter, GraphicalReporter, JsonReporter,
|
||||
UnixReporter,
|
||||
},
|
||||
Error, MinifiedFileError, Severity,
|
||||
Error, OxcDiagnostic, Severity,
|
||||
};
|
||||
|
||||
pub type DiagnosticTuple = (PathBuf, Vec<Error>);
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue