Add more detailed error reporting around invalid projects

This commit is contained in:
Lucien Greathouse
2017-12-13 11:55:30 -08:00
parent b74ba141d1
commit 59b2401c2c
3 changed files with 31 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
# Rojo Change Log # Rojo Change Log
## Current Master ## Current Master
* *No changes* * Improved error reporting when invalid JSON is found in a `rojo.json` project
* These messages are passed on from Serde
## 0.3.0 ## 0.3.0
* Factored out the plugin into a separate repository * Factored out the plugin into a separate repository

View File

@@ -25,7 +25,7 @@ use std::thread;
use core::Config; use core::Config;
use pathext::canonicalish; use pathext::canonicalish;
use project::Project; use project::{Project, ProjectLoadError};
use vfs::Vfs; use vfs::Vfs;
use vfs_watch::VfsWatcher; use vfs_watch::VfsWatcher;
@@ -98,8 +98,32 @@ fn main() {
println!("Using project from {}", project_path.display()); println!("Using project from {}", project_path.display());
v v
}, },
Err(_) => { Err(err) => {
println!("Using default project..."); match err {
ProjectLoadError::InvalidJson(serde_err) => {
eprintln!(
"Found invalid JSON!\nProject in: {}\nError: {}",
project_path.display(),
serde_err,
);
std::process::exit(1);
},
ProjectLoadError::FailedToOpen | ProjectLoadError::FailedToRead => {
eprintln!("Found project file, but failed to read it!");
eprintln!(
"Check the permissions of the project file at\n{}",
project_path.display(),
);
std::process::exit(1);
},
_ => {
// Any other error is fine; use the default project.
},
}
println!("Found no project file, using default project...");
Project::default() Project::default()
}, },
}; };

View File

@@ -13,7 +13,7 @@ pub enum ProjectLoadError {
DidNotExist, DidNotExist,
FailedToOpen, FailedToOpen,
FailedToRead, FailedToRead,
Invalid, InvalidJson(serde_json::Error),
} }
#[derive(Debug)] #[derive(Debug)]
@@ -116,7 +116,7 @@ impl Project {
match serde_json::from_str(&contents) { match serde_json::from_str(&contents) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => return Err(ProjectLoadError::Invalid), Err(e) => return Err(ProjectLoadError::InvalidJson(e)),
} }
} }