This commit is contained in:
howardwu 2020-04-25 00:25:35 -07:00
parent fb4e5ee8e1
commit 2f1e5acec4
3 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,7 @@ use crate::errors::{InitError, MainFileError, ManifestError, SourceDirectoryErro
#[derive(Debug, Fail)]
pub enum CLIError {
#[fail(display = "{}: {}", _0, _1)]
Crate(&'static str, String),
@ -16,6 +17,7 @@ pub enum CLIError {
#[fail(display = "{}", _0)]
SourceDirectoryError(SourceDirectoryError),
}
impl From<InitError> for CLIError {

View File

@ -2,8 +2,20 @@ use std::io;
#[derive(Debug, Fail)]
pub enum MainFileError {
#[fail(display = "{}: {}", _0, _1)]
Crate(&'static str, String),
#[fail(display = "creating: {}", _0)]
Creating(io::Error),
#[fail(display = "writing: {}", _0)]
Writing(io::Error),
}
impl From<std::io::Error> for MainFileError {
fn from(error: std::io::Error) -> Self {
MainFileError::Crate("std::io", format!("{}", error))
}
}

View File

@ -40,9 +40,8 @@ impl MainFile {
path.push(PathBuf::from(FILE_NAME_DEFAULT));
}
let mut file = File::create(&path).map_err(MainFileError::Creating)?;
file.write_all(self.template().as_bytes())
.map_err(MainFileError::Writing)
let mut file = File::create(&path)?;
Ok(file.write_all(self.template().as_bytes())?)
}
fn template(&self) -> String {