From aa4039a2e76c594f0f02e332a25d9ad68b777d03 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Mon, 16 Mar 2020 23:37:00 -0700 Subject: [PATCH] bye snafu --- Cargo.lock | 1 - Cargo.toml | 1 - src/project.rs | 36 ++++++++++++++++++------------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e4dcb5a..8dd984dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1705,7 +1705,6 @@ dependencies = [ "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)", - "snafu 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index ce3d70fe..4555ef1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,6 @@ ritz = "0.1.0" rlua = "0.17.0" serde = { version = "1.0", features = ["derive", "rc"] } serde_json = "1.0" -snafu = "0.6.0" structopt = "0.3.5" termcolor = "1.0.5" thiserror = "1.0.11" diff --git a/src/project.rs b/src/project.rs index f6cc92b5..bbdb5398 100644 --- a/src/project.rs +++ b/src/project.rs @@ -6,22 +6,26 @@ use std::{ use rbx_dom_weak::UnresolvedRbxValue; use serde::{Deserialize, Serialize}; -use snafu::{ResultExt, Snafu}; +use thiserror::Error; use crate::glob::Glob; static PROJECT_FILENAME: &str = "default.project.json"; /// Error type returned by any function that handles projects. -#[derive(Debug, Snafu)] -pub struct ProjectError(Error); +#[derive(Debug, Error)] +#[error(transparent)] +pub struct ProjectError(#[from] Error); -#[derive(Debug, Snafu)] +#[derive(Debug, Error)] enum Error { - /// A general IO error occurred. - Io { source: io::Error, path: PathBuf }, + #[error("Rojo project I/O error")] + Io { + #[from] + source: io::Error, + }, - /// An error with JSON parsing occurred. + #[error("Error parsing Rojo project")] Json { source: serde_json::Error, path: PathBuf, @@ -125,14 +129,14 @@ impl Project { } } - fn load_exact(project_file_location: &Path) -> Result { - let contents = fs::read_to_string(project_file_location).context(Io { - path: project_file_location, - })?; + fn load_exact(project_file_location: &Path) -> Result { + let contents = fs::read_to_string(project_file_location)?; - let mut project: Project = serde_json::from_str(&contents).context(Json { - path: project_file_location, - })?; + let mut project: Project = + serde_json::from_str(&contents).map_err(|source| Error::Json { + source, + path: project_file_location.to_owned(), + })?; project.file_location = project_file_location.to_path_buf(); project.check_compatibility(); @@ -140,10 +144,6 @@ impl Project { Ok(project) } - pub fn save(&self) -> Result<(), ProjectError> { - unimplemented!() - } - /// Checks if there are any compatibility issues with this project file and /// warns the user if there are any. fn check_compatibility(&self) {