use cargo::{execute_main_without_stdin};
use cargo::core::source::{Source,SourceId};
use cargo::sources::git::{GitSource};
-use cargo::util::{Config, CliResult, CliError, Require};
+use cargo::util::{Config, CliResult, CliError, Require, human};
use url::Url;
#[deriving(PartialEq,Clone,Decodable)]
let Options { url, reference, .. } = options;
let url: Url = try!(from_str(url.as_slice())
- .require(|| format!("The URL `{}` you passed was not a valid URL", url))
+ .require(|| human(format!("The URL `{}` you passed was not a valid URL", url)))
.map_err(|e| CliError::from_boxed(e, 1)));
let source_id = SourceId::for_git(&url, reference.as_slice());
use serialize::Encodable;
use cargo::{NoFlags,execute_main_without_stdin,handle_error};
use cargo::util::important_paths::find_project;
-use cargo::util::{CliError, CliResult, Require, config};
+use cargo::util::{CliError, CliResult, Require, config, human};
fn main() {
execute();
fn process(args: Vec<String>) -> CliResult<(String, Vec<String>)> {
let args: Vec<String> = Vec::from_slice(args.tail());
- let head = try!(args.iter().nth(0).require(|| "No subcommand found").map_err(|err| CliError::from_boxed(err, 1))).to_str();
+ let head = try!(args.iter().nth(0).require(|| human("No subcommand found")).map_err(|err| CliError::from_boxed(err, 1))).to_str();
let tail = Vec::from_slice(args.tail());
Ok((head, tail))
let root = try!(find_project(os::getcwd(), "Cargo.toml").map_err(|e| CliError::from_boxed(e, 1)));
let string = try!(root.as_str()
- .require(|| "Your project path contains characters not representable in Unicode")
+ .require(|| human("Your project path contains characters not representable in Unicode"))
.map_err(|e| CliError::from_boxed(e, 1)));
Ok(Some(ProjectLocation { root: string.to_str() }))
use serialize::{Decoder,Encoder,Decodable,Encodable,json};
use std::io;
use hammer::{FlagDecoder,FlagConfig,HammerError};
-pub use util::{CliError, CliResult};
+pub use util::{CliError, CliResult, human};
macro_rules! some(
($e:expr) => (
use core::registry::PackageRegistry;
use ops;
use sources::{PathSource};
-use util::{CargoResult, Wrap, config, error};
+use util::{CargoResult, Wrap, config, error, human};
pub fn compile(manifest_path: &Path) -> CargoResult<()> {
log!(4, "compile; manifest-path={}", manifest_path.display());
let source_ids = package.get_source_ids();
let mut registry = try!(PackageRegistry::new(source_ids, override_ids));
- let resolved = try!(resolver::resolve(package.get_dependencies(), &mut registry).wrap("unable to resolve dependencies"));
+ let resolved = try!(resolver::resolve(package.get_dependencies(), &mut registry).wrap(human("unable to resolve dependencies")));
- let packages = try!(registry.get(resolved.as_slice()).wrap("unable to get packages from source"));
+ let packages = try!(registry.get(resolved.as_slice()).wrap(human("unable to get packages from source")));
debug!("packages={}", packages);
use util::{CargoResult, human};
pub fn read_manifest(contents: &[u8], source_id: &SourceId) -> CargoResult<(Manifest, Vec<Path>)> {
- util::toml::to_manifest(contents, source_id).map_err(human)
+ util::toml::to_manifest(contents, source_id).map_err(|err| human(err.to_str()))
}
pub fn read_package(path: &Path, source_id: &SourceId) -> CargoResult<(Package, Vec<Path>)> {
use std::path::Path;
use core::{Package,PackageSet,Target};
use util;
-use util::{CargoResult, CargoError, ProcessBuilder, error, human};
+use util::{CargoResult, ProcessBuilder, error, human};
type Args = Vec<String>;
let rustc = prepare_rustc(root, target, *crate_type, dest, deps);
try!(if verbose {
- rustc.exec().map_err(|err| {
- log!(5, "exec failed; error={}", err.description());
- human(err)
- })
+ rustc.exec().map_err(|err| human(err.to_str()))
} else {
- rustc.exec_with_output().and(Ok(())).map_err(|err| {
- log!(5, "exec_with_output failed; error={}", err.description());
- human(err)
- })
+ rustc.exec_with_output().and(Ok(())).map_err(|err| human(err.to_str()))
});
}
use url::Url;
-use util::{CargoResult, ChainError, ProcessBuilder, process};
+use util::{CargoResult, ChainError, ProcessBuilder, process, human};
use std::fmt;
use std::fmt::{Show,Formatter};
use std::str;
let dirname = Path::new(self.location.dirname());
cargo_try!(mkdir_recursive(&dirname, UserDir).chain_error(||
- format!("Couldn't mkdir {}", Path::new(self.location.dirname()).display())));
+ human(format!("Couldn't mkdir {}", Path::new(self.location.dirname()).display()))));
if self.location.exists() {
cargo_try!(rmdir_recursive(&self.location).chain_error(||
- format!("Couldn't rmdir {}", Path::new(&self.location).display())));
+ human(format!("Couldn't rmdir {}", Path::new(&self.location).display()))));
}
git!(dirname, "clone --no-checkout --quiet {} {}", self.get_source().display(), self.location.display());
}
fn git_inherit(path: &Path, str: String) -> CargoResult<()> {
- git(path, str.as_slice()).exec().chain_error(|| format!("Executing `git {}` failed", str))
+ git(path, str.as_slice()).exec().chain_error(|| human(format!("Executing `git {}` failed", str)))
}
fn git_output(path: &Path, str: String) -> CargoResult<String> {
let output = cargo_try!(git(path, str.as_slice()).exec_with_output().chain_error(||
- format!("Executing `git {}` failed", str)));
+ human(format!("Executing `git {}` failed", str))));
Ok(to_str(output.output.as_slice()).as_slice().trim_right().to_str())
}
use std::collections::HashMap;
use serialize::{Encodable,Encoder};
use toml;
-use util::{CargoResult, ChainError, Require, error, internal_error};
+use util::{CargoResult, ChainError, Require, error, internal_error, human};
pub struct Config {
home_path: Path
pub fn new() -> CargoResult<Config> {
Ok(Config {
home_path: cargo_try!(os::homedir()
- .require(|| "Couldn't find the home directory"))
+ .require(|| human("Couldn't find the home directory")))
})
}
}
}
-impl CargoError for &'static str {
- fn description(&self) -> String { self.to_str() }
- fn is_human(&self) -> bool { true }
-}
-
-impl CargoError for String {
- fn description(&self) -> String { self.to_str() }
- fn is_human(&self) -> bool { true }
-}
-
impl CargoError for IoError {
fn description(&self) -> String { self.to_str() }
}
Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(),
None => "never executed".to_str()
};
- write!(f, "process failed: `{}` (status={})", self.command, exit)
+ write!(f, "{} (status={})", self.msg, exit)
}
}
}
impl CliError {
- pub fn new<E: CargoError + 'static>(error: E, code: uint) -> CliError {
+ pub fn new<S: Str>(error: S, code: uint) -> CliError {
+ let error = human(error.as_slice().to_str());
+ CliError::from_boxed(error, code)
+ }
+
+ pub fn from_error<E: CargoError + 'static>(error: E, code: uint) -> CliError {
let error = box error as Box<CargoError>;
CliError::from_boxed(error, code)
}
let error = if error.is_human() {
error
} else {
- chain(error, "An unknown error occurred")
+ chain(error, human("An unknown error occurred"))
};
CliError { error: error, exit_code: code }
} as Box<CargoError>
}
-pub fn human<E: CargoError>(error: E) -> Box<CargoError> {
- let mut concrete = error.concrete();
- concrete.is_human = true;
- box concrete as Box<CargoError>
+pub fn human<S: Str>(error: S) -> Box<CargoError> {
+ box ConcreteCargoError {
+ description: error.as_slice().to_str(),
+ detail: None,
+ cause: None,
+ is_human: true
+ } as Box<CargoError>
}
pub fn chain<E: CargoError>(original: Box<CargoError>, update: E) -> Box<CargoError> {
use core::{SourceId,GitKind};
use core::manifest::{LibKind,Lib};
use core::{Summary,Manifest,Target,Dependency,PackageId};
-use util::{CargoResult, Require, error};
+use util::{CargoResult, Require, error, human};
pub fn to_manifest(contents: &[u8], source_id: &SourceId) -> CargoResult<(Manifest, Vec<Path>)> {
let root = try!(toml::parse_from_bytes(contents).map_err(|_| error("Cargo.toml is not valid Toml")));
let deps = match deps {
Some(deps) => {
- let table = try!(deps.get_table().require(|| "dependencies must be a table")).clone();
+ let table = try!(deps.get_table().require(|| human("dependencies must be a table"))).clone();
let mut deps: HashMap<String, TomlDependency> = HashMap::new();
for (k, v) in table.iter() {
let v = try!(v.get_str()
- .require(|| "dependency values must be string"));
+ .require(|| human("dependency values must be string")));
details.insert(k.clone(), v.clone());
}
let version = try!(details.find_equiv(&"version")
- .require(|| "dependencies must include a version")).clone();
+ .require(|| human("dependencies must include a version"))).clone();
deps.insert(k.clone(), DetailedDep(DetailedTomlDependency {
version: version,