Skip to content

Commit

Permalink
refactor: rename errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Apr 17, 2024
1 parent 588de5b commit e64e811
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
10 changes: 5 additions & 5 deletions crates/lsp/src/reporting/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use tower_lsp::lsp_types as lsp;
use abs_path::AbsPath;
use witcherscript_analysis::diagnostics::{Diagnostic, DiagnosticBody};
use witcherscript_project::{manifest::ManifestParseError, redkit, FileError};
use witcherscript_project::{manifest, redkit, FileError};
use crate::Backend;
use super::Reporter;

Expand Down Expand Up @@ -38,14 +38,14 @@ impl IntoLspDiagnostic for FileError<std::io::Error> {
}
}

impl IntoLspDiagnostic for FileError<ManifestParseError> {
impl IntoLspDiagnostic for FileError<manifest::Error> {
fn into_lsp_diagnostic(self) -> lsp::Diagnostic {
let error = self.error.as_ref();

let range = match error {
ManifestParseError::Io(_) => lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),
ManifestParseError::Toml { range, msg: _ } => range.clone(),
ManifestParseError::InvalidNameField { range } => range.clone(),
manifest::Error::Io(_) => lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 1)),
manifest::Error::Toml { range, msg: _ } => range.clone(),
manifest::Error::InvalidNameField { range } => range.clone(),
};

let message = error.to_string();
Expand Down
2 changes: 1 addition & 1 deletion crates/lsp/src/tasks/content_indexing_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl Backend {
ContentGraphError::Io(err) => {
self.reporter.log_warning(format!("Content scanning issue at {}: {}", err.path.display(), err.error)).await;
},
ContentGraphError::ManifestParse(err) => {
ContentGraphError::ManifestRead(err) => {
self.reporter.push_diagnostic(&err.path, err.clone().into_lsp_diagnostic());
},
ContentGraphError::RedkitManifestRead(err) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/project/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use abs_path::AbsPath;
use thiserror::Error;

use crate::manifest::{Manifest, ManifestParseError};
use crate::manifest::{self, Manifest};
use crate::source_tree::SourceTree;
use crate::{redkit, FileError};

Expand Down Expand Up @@ -223,7 +223,7 @@ pub enum ContentScanError {
#[error(transparent)]
Io(#[from] FileError<std::io::Error>),
#[error(transparent)]
ManifestParse(#[from] FileError<ManifestParseError>), //todo rename to ManifestRead
ManifestParse(#[from] FileError<manifest::Error>), //todo rename to ManifestRead
#[error(transparent)]
RedkitManifestRead(#[from] FileError<redkit::manifest::Error>),
#[error("this is not content directory")]
Expand Down
15 changes: 7 additions & 8 deletions crates/project/src/content_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ use thiserror::Error;
use lsp_types as lsp;
use abs_path::AbsPath;
use crate::content::{try_make_content, ContentScanError, ProjectDirectory, RedkitProjectDirectory};
use crate::{redkit, Content, ContentScanner, FileError};
use crate::manifest::{DependencyValue, ManifestParseError};
use crate::{manifest, redkit, Content, ContentScanner, FileError};


#[derive(Debug, Clone, Error)]
pub enum ContentGraphError {
#[error(transparent)]
Io(#[from] FileError<std::io::Error>),
#[error(transparent)]
ManifestParse(#[from] FileError<ManifestParseError>), //TODO rename to ManifestRead
ManifestRead(#[from] FileError<manifest::Error>),
#[error(transparent)]
RedkitManifestRead(#[from] FileError<redkit::manifest::Error>),
#[error("project dependency at path \"{}\" could not be found", .content_path.display())]
Expand Down Expand Up @@ -225,7 +224,7 @@ impl ContentGraph {
self.errors.push(ContentGraphError::Io(err));
},
ContentScanError::ManifestParse(err) => {
self.errors.push(ContentGraphError::ManifestParse(err))
self.errors.push(ContentGraphError::ManifestRead(err))
},
ContentScanError::RedkitManifestRead(err) => {
self.errors.push(ContentGraphError::RedkitManifestRead(err))
Expand Down Expand Up @@ -258,7 +257,7 @@ impl ContentGraph {
self.errors.push(ContentGraphError::Io(err));
},
ContentScanError::ManifestParse(err) => {
self.errors.push(ContentGraphError::ManifestParse(err))
self.errors.push(ContentGraphError::ManifestRead(err))
},
ContentScanError::RedkitManifestRead(err) => {
self.errors.push(ContentGraphError::RedkitManifestRead(err))
Expand Down Expand Up @@ -299,12 +298,12 @@ impl ContentGraph {
if let Some(proj) = content.as_any().downcast_ref::<ProjectDirectory>() {
for entry in proj.manifest().dependencies.iter() {
match &entry.value {
DependencyValue::FromRepo(active) => {
manifest::DependencyValue::FromRepo(active) => {
if *active {
self.link_dependencies_value_from_repo(node_idx, repo_nodes, proj.manifest_path(), &entry.name, &entry.name_range);
}
},
DependencyValue::FromPath { path } => {
manifest::DependencyValue::FromPath { path } => {
self.link_dependencies_value_from_path(node_idx, repo_nodes, proj.manifest_path(), &entry.name, &entry.name_range, path, &entry.value_range);
},
}
Expand Down Expand Up @@ -444,7 +443,7 @@ impl ContentGraph {
self.errors.push(ContentGraphError::Io(err));
},
ContentScanError::ManifestParse(err) => {
self.errors.push(ContentGraphError::ManifestParse(err));
self.errors.push(ContentGraphError::ManifestRead(err));
},
ContentScanError::RedkitManifestRead(err) => {
self.errors.push(ContentGraphError::RedkitManifestRead(err))
Expand Down
10 changes: 5 additions & 5 deletions crates/project/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum DependencyValue {
impl Manifest {
pub const FILE_NAME: &'static str = "witcherscript.toml";

pub fn from_file(path: &AbsPath) -> Result<Self, ManifestParseError> {
pub fn from_file(path: &AbsPath) -> Result<Self, Error> {
let mut f = File::open(path).map_err(|err| Arc::new(err))?;

let mut buff = String::new();
Expand All @@ -82,14 +82,14 @@ impl Manifest {
}

impl FromStr for Manifest {
type Err = ManifestParseError;
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let rope = Rope::from_str(s);
let raw: Result<raw::Manifest, toml::de::Error> = toml::from_str(s);

if let Err(err) = raw {
return Err(ManifestParseError::Toml {
return Err(Error::Toml {
range: lsp::Range::from_raw(err.span().unwrap_or_default(), &rope),
msg: err.to_string()
});
Expand All @@ -99,7 +99,7 @@ impl FromStr for Manifest {

// validate content name
if !Self::validate_content_name(&manifest.content.name) {
return Err(ManifestParseError::InvalidNameField {
return Err(Error::InvalidNameField {
range: manifest.content.name_range.clone()
})
}
Expand All @@ -109,7 +109,7 @@ impl FromStr for Manifest {
}

#[derive(Debug, Clone, Error)]
pub enum ManifestParseError { //TODO rename to just Error
pub enum Error {
#[error("file access error: {}", .0)]
Io(#[from] Arc<io::Error>),
#[error("TOML file parsing error: {msg}")]
Expand Down

0 comments on commit e64e811

Please sign in to comment.