Skip to content

Commit b6fff53

Browse files
committed
Improving error reports
1 parent 53cd39f commit b6fff53

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/main.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::yaml::{
1111
get_build_lang, get_build_os, get_lang, get_no_deploy, get_os, get_update, get_yaml,
1212
};
1313
use exitfailure::ExitFailure;
14+
use failure::ResultExt;
1415
use log::{debug, error, info};
1516
use std::fmt::Display;
1617
use std::path::PathBuf;
@@ -148,29 +149,44 @@ fn main() -> Result<(), ExitFailure> {
148149
.to_str()
149150
.unwrap_or("Filename not convertible")
150151
);
151-
let config = crate::config::get_config(&opt.configfile)?;
152+
let config = crate::config::get_config(&opt.configfile).with_context(|_| {
153+
format!(
154+
"could not parse the file {}",
155+
opt.configfile.to_str().unwrap_or("file name not printable")
156+
)
157+
})?;
152158
let prj = Project {
153159
owner: opt.user_name.clone(),
154160
project: opt.project_name.clone(),
155161
};
156-
let (rs, _) = get_status(&prj, &config.tokens.github)?;
162+
let (rs, _) = get_status(&prj, &config.tokens.github).with_context(|_| {
163+
format!(
164+
"Fecth repository data failed for user {} project {}",
165+
prj.owner, prj.project,
166+
)
167+
})?;
157168
println!("github repository information:\n{}", rs);
158169
/* fetch the repo to read the .bsd-ci file */
159-
let path = crate::pot::fetch_git_in_fscomp(&prj, &rs, &opt)?;
170+
let path = crate::pot::fetch_git_in_fscomp(&prj, &rs, &opt).with_context(|_| {
171+
"Failed to create a ZFS dataset with the project in it\n Is pot installed?\n Are you root?"
172+
})?;
160173

161174
println!("Git repo fetched in {}", path);
162175

163176
let mut build_queue = Vec::new();
164177
let mut build_opt = BuildOpt::default();
165-
let yaml_string = get_yaml(&path)?;
166-
let docs = YamlLoader::load_from_str(&yaml_string)?;
178+
let yaml_string =
179+
get_yaml(&path).with_context(|_| "Error accessing the yaml file in the project")?;
180+
let docs = YamlLoader::load_from_str(&yaml_string)
181+
.with_context(|_| "Error parsing the yaml file in the project")?;
167182
for d in docs {
168183
let h = d.into_hash().unwrap();
169184
debug!("{:?}", h);
170-
let lang = get_lang(&h)?;
171-
let os = get_os(&h)?;
185+
let lang = get_lang(&h).with_context(|_| "Invalid YAML")?;
186+
let os = get_os(&h).with_context(|_| "Invalid YAML")?;
172187
let build_lang = match lang.as_ref() {
173-
"rust" => get_build_lang("rust", &h)?,
188+
"rust" => get_build_lang("rust", &h)
189+
.with_context(|_| format!("Ivalid YAML for language {}", lang))?,
174190
_ => {
175191
return Err(ExitFailure::from(ParseError::GenericError {
176192
msg: "language not supported".to_string(),

0 commit comments

Comments
 (0)