Skip to content

Commit

Permalink
refactor: cleaned up workspaceError enum in biome_service/diagnostics…
Browse files Browse the repository at this point in the history
….rs (#4681)

Co-authored-by: Emanuele Stoppa <[email protected]>
Co-authored-by: Carson McManus <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent e52c40c commit d808057
Showing 1 changed file with 1 addition and 59 deletions.
60 changes: 1 addition & 59 deletions crates/biome_service/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ use std::process::{ExitCode, Termination};
/// Generic errors thrown during biome operations
#[derive(Deserialize, Diagnostic, Serialize)]
pub enum WorkspaceError {
/// Can't export the report of the CLI into a file
ReportNotSerializable(ReportNotSerializable),
/// The project contains uncommitted changes
DirtyWorkspace(DirtyWorkspace),
/// The file does not exist in the [crate::Workspace]
NotFound(NotFound),
/// A file is not supported. It contains the language and path of the file
Expand All @@ -40,8 +36,6 @@ pub enum WorkspaceError {
FormatWithErrorsDisabled(FormatWithErrorsDisabled),
/// The file could not be analyzed because a rule caused an error.
RuleError(RuleError),
/// Thrown when Biome can't read a generic directory
CantReadDirectory(CantReadDirectory),
/// Thrown when Biome can't read a generic file
CantReadFile(CantReadFile),
/// Error thrown when validating the configuration. Once deserialized, further checks have to be done.
Expand Down Expand Up @@ -171,25 +165,6 @@ impl From<CantLoadExtendFile> for WorkspaceError {
}
}

#[derive(Debug, Serialize, Deserialize, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
message = "Uncommitted changes in repository"
)]
pub struct DirtyWorkspace;

#[derive(Debug, Serialize, Deserialize, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
message(
message("The report can't be serialized, here's why: "{self.reason}),
description = "The report can't be serialized, here's why: {reason}"
)
)]
pub struct ReportNotSerializable {
reason: String,
}

#[derive(Debug, Serialize, Deserialize, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
Expand All @@ -205,19 +180,6 @@ pub struct NotFound;
)]
pub struct FormatWithErrorsDisabled;

#[derive(Debug, Serialize, Deserialize, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
message(
message("Biome couldn't read the following directory, maybe for permissions reasons or it doesn't exist: "{self.path}),
description = "Biome couldn't read the following directory, maybe for permissions reasons or it doesn't exist: {path}"
)
)]
pub struct CantReadDirectory {
#[location(resource)]
path: String,
}

#[derive(Debug, Serialize, Deserialize, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
Expand Down Expand Up @@ -538,8 +500,7 @@ impl Advices for ProtectedFileAdvice {
#[cfg(test)]
mod test {
use crate::diagnostics::{
CantReadDirectory, CantReadFile, DirtyWorkspace, FileIgnored, FileTooLarge, NotFound,
SourceFileNotSupported,
CantReadFile, FileIgnored, FileTooLarge, NotFound, SourceFileNotSupported,
};
use crate::file_handlers::DocumentFileSource;
use crate::{TransportError, WorkspaceError};
Expand All @@ -564,14 +525,6 @@ mod test {
assert_eq!(std::mem::size_of::<WorkspaceError>(), 96)
}

#[test]
fn dirty_workspace() {
snap_diagnostic(
"dirty_workspace",
WorkspaceError::DirtyWorkspace(DirtyWorkspace).into(),
)
}

#[test]
fn file_ignored() {
snap_diagnostic(
Expand All @@ -583,17 +536,6 @@ mod test {
)
}

#[test]
fn cant_read_directory() {
snap_diagnostic(
"cant_read_directory",
WorkspaceError::CantReadDirectory(CantReadDirectory {
path: "example/".to_string(),
})
.with_file_path("example/"),
)
}

#[test]
fn cant_read_file() {
snap_diagnostic(
Expand Down

0 comments on commit d808057

Please sign in to comment.