pub fn new() -> CargoResult<Config> {
Ok(Config {
home_path: try!(os::homedir().require(|| {
- human("Couldn't find the home directory")
+ human("Cargo couldn't find your home directory. \
+ This probably means that $HOME was not set.")
}))
})
}
pub fn get_config(pwd: Path, key: &str) -> CargoResult<ConfigValue> {
find_in_tree(&pwd, |file| extract_config(file, key)).map_err(|_|
- internal(format!("config key not found; key={}", key)))
+ human(format!("`{}` not found in your configuration", key)))
}
pub fn all_configs(pwd: Path) -> CargoResult<HashMap<String, ConfigValue>> {
let mut map = HashMap::new();
- try!(walk_tree(&pwd, |file| {
- extract_all_configs(file, &mut map)
- }));
+ try!(walk_tree(&pwd, |file| extract_all_configs(file, &mut map)).map_err(|_|
+ human("Couldn't load Cargo configuration")));
+
Ok(map)
}
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = try!(io::fs::File::open(&possible).chain_error(|| {
- internal("could not open file")
- }));
+ let file = try!(io::fs::File::open(&possible));
+
match walk(file) {
Ok(res) => return Ok(res),
_ => ()
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = try!(io::fs::File::open(&possible).chain_error(|| {
- internal("could not open file")
- }));
+ let file = try!(io::fs::File::open(&possible));
+
match walk(file) {
Err(_) => err = false,
_ => ()
-use std::io::process::{Command,ProcessOutput,ProcessExit,ExitStatus,ExitSignal};
+use std::io::process::{ProcessOutput, ProcessExit, ExitStatus, ExitSignal};
use std::io::IoError;
use std::fmt;
use std::fmt::{Show, Formatter, FormatError};
pub struct ProcessError {
pub msg: String,
- pub command: String,
pub exit: Option<ProcessExit>,
pub output: Option<ProcessOutput>,
pub detail: Option<String>,
}
pub fn process_error<S: Str>(msg: S,
- command: &Command,
+ cause: Option<IoError>,
status: Option<&ProcessExit>,
output: Option<&ProcessOutput>) -> ProcessError {
ProcessError {
msg: msg.as_slice().to_str(),
- command: command.to_str(),
exit: status.map(|o| o.clone()),
output: output.map(|o| o.clone()),
detail: None,
- cause: None
+ cause: cause.map(|c| box c as Box<CargoError>)
}
}
-use util::{CargoResult, CargoError, internal_error};
+use util::{CargoResult, human};
pub fn find_project(pwd: Path, file: &str) -> CargoResult<Path> {
let mut current = pwd.clone();
if !current.pop() { break; }
}
- Err(manifest_missing_err(&pwd, file.as_slice()))
-}
-
-fn manifest_missing_err(pwd: &Path, file: &str) -> Box<CargoError> {
- internal_error("manifest not found",
- format!("pwd={}; file={}", pwd.display(), file))
+ Err(human(format!("no manifest found in `{}`", pwd.display())))
}
let msg = || format!("Could not execute process `{}`",
self.debug_string());
- let exit = try!(command.status().map_err(|_| {
- process_error(msg(), &command, None, None)
- }));
+ let exit = try!(command.status().map_err(|e|
+ process_error(msg(), Some(e), None, None)));
if exit.success() {
Ok(())
} else {
- Err(process_error(msg(), &command, Some(&exit), None))
+ Err(process_error(msg(), None, Some(&exit), None))
}
}
let msg = || format!("Could not execute process `{}`",
self.debug_string());
- let output = try!(command.output().map_err(|_| {
- process_error(msg(), &command, None, None)
+ let output = try!(command.output().map_err(|e| {
+ process_error(msg(), Some(e), None, None)
}));
if output.status.success() {
Ok(output)
} else {
- Err(process_error(msg(), &command, Some(&output.status),
+ Err(process_error(msg(), None, Some(&output.status),
Some(&output)))
}
}