use std::fmt;
use std::str::CharOffsets;
use semver::Version;
-use util::{CargoResult, error};
+use util::{CargoResult, internal};
#[deriving(PartialEq,Clone)]
pub struct VersionReq {
}
if lexer.is_error() {
- return Err(error("invalid version requirement"));
+ return Err(internal("invalid version requirement"));
}
predicates.push(try!(builder.build()));
fn set_sigil(&mut self, sigil: &str) -> CargoResult<()> {
if self.op.is_some() {
- return Err(error("op already set"));
+ return Err(internal("op already set"));
}
match Op::from_sigil(sigil) {
Some(op) => self.op = Some(op),
- _ => return Err(error("invalid sigil"))
+ _ => return Err(internal("invalid sigil"))
}
Ok(())
fn build(&self) -> CargoResult<Predicate> {
let op = match self.op {
Some(x) => x,
- None => return Err(error("op required"))
+ None => return Err(internal("op required"))
};
let major = match self.major {
Some(x) => x,
- None => return Err(error("major version required"))
+ None => return Err(internal("major version required"))
};
Ok(Predicate {
let n = (c as uint) - ('0' as uint);
if n > 9 {
- return Err(error("version components must be numeric"));
+ return Err(internal("version components must be numeric"));
}
ret *= 10;
use core::registry::PackageRegistry;
use ops;
use sources::{PathSource};
-use util::{CargoResult, Wrap, config, error, human};
+use util::{CargoResult, Wrap, config, internal, human};
pub fn compile(manifest_path: &Path) -> CargoResult<()> {
log!(4, "compile; manifest-path={}", manifest_path.display());
let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
let paths: Vec<Path> = match config_paths.get_value() {
- &config::String(_) => return Err(error("The path was configured as a String instead of a List")),
+ &config::String(_) => return Err(internal("The path was configured as a String instead of a List")),
&config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
};
use std::path::Path;
use core::{Package,PackageSet,Target};
use util;
-use util::{CargoResult, ProcessBuilder, error, human};
+use util::{CargoResult, ChainError, ProcessBuilder, internal, human};
type Args = Vec<String>;
}
fn mk_target(target: &Path) -> CargoResult<()> {
- io::fs::mkdir_recursive(target, io::UserRWX)
- .map_err(|_| error("could not create target directory"))
+ io::fs::mkdir_recursive(target, io::UserRWX).chain_error(|| internal("could not create target directory"))
}
fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool) -> CargoResult<()> {
fn topsort(deps: &PackageSet) -> CargoResult<PackageSet> {
match deps.sort() {
Some(deps) => Ok(deps),
- None => return Err(error("circular dependency detected"))
+ None => return Err(internal("circular dependency detected"))
}
}
use std::fmt::{Show,Formatter};
use core::{Package,PackageId,Summary,SourceId,Source};
use ops;
-use util::{CargoResult, error};
+use util::{CargoResult, internal};
pub struct PathSource {
id: SourceId,
log!(5, "get_root_package; source={}", self);
if !self.updated {
- return Err(error("source has not been updated"))
+ return Err(internal("source has not been updated"))
}
match self.packages.as_slice().head() {
Some(pkg) => Ok(pkg.clone()),
- None => Err(error("no package found in source"))
+ None => Err(internal("no package found in source"))
}
}
}
use std::collections::HashMap;
use serialize::{Encodable,Encoder};
use toml;
-use util::{CargoResult, ChainError, Require, error, internal_error, human};
+use util::{CargoResult, ChainError, Require, internal, human};
pub struct Config {
home_path: Path
}
pub fn get_config(pwd: Path, key: &str) -> CargoResult<ConfigValue> {
- find_in_tree(&pwd, |file| extract_config(file, key))
- .map_err(|_| internal_error("config key not found", format!("key={}", key)))
+ find_in_tree(&pwd, |file| extract_config(file, key)).map_err(|_|
+ internal(format!("config key not found; key={}", key)))
}
pub fn all_configs(pwd: Path) -> CargoResult<HashMap<String, ConfigValue>> {
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| error("could not open file")));
+ let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| internal("could not open file")));
match walk(file) {
Ok(res) => return Ok(res),
_ => ()
if !current.pop() { break; }
}
- Err(error(""))
+ Err(internal(""))
}
fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult<()> {
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| error("could not open file")));
+ let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| internal("could not open file")));
match walk(file) {
Err(_) => err = false,
_ => ()
}
}
- if err { return Err(error("")); }
+ if err { return Err(internal("")); }
if !current.pop() { break; }
}
let path = file.path().clone();
let mut buf = io::BufferedReader::new(file);
let root = cargo_try!(toml::parse_from_buffer(&mut buf));
- let val = cargo_try!(root.lookup(key).require(|| error("")));
+ let val = cargo_try!(root.lookup(key).require(|| internal("")));
let v = match val {
&toml::String(ref val) => String(val.clone()),
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
- _ => return Err(error(""))
+ _ => return Err(internal(""))
};
Ok(ConfigValue{ value: v, path: vec!(path) })
let path = file.path().clone();
let mut buf = io::BufferedReader::new(file);
let root = cargo_try!(toml::parse_from_buffer(&mut buf).chain_error(||
- error(format!("could not parse Toml manifest; path={}", path.display()))));
+ internal(format!("could not parse Toml manifest; path={}", path.display()))));
let table = cargo_try!(root.get_table().require(||
- error(format!("could not parse Toml manifest; path={}", path.display()))));
+ internal(format!("could not parse Toml manifest; path={}", path.display()))));
for (key, value) in table.iter() {
match value {
});
cargo_try!(merge_array(config, val.as_slice(), &path).chain_error(||
- error(format!("The `{}` key in your config", key))));
+ internal(format!("The `{}` key in your config", key))));
},
_ => ()
}
fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &Path) -> CargoResult<()> {
match existing.value {
- String(_) => return Err(error("should be an Array, but it was a String")),
+ String(_) => return Err(internal("should be an Array, but it was a String")),
List(ref mut list) => {
let new_list: Vec<CargoResult<String>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
if new_list.iter().any(|v| v.is_err()) {
- return Err(error("should be an Array of Strings, but was an Array of other values"));
+ return Err(internal("should be an Array of Strings, but was an Array of other values"));
} else {
let new_list: Vec<String> = new_list.move_iter().map(|v| v.unwrap()).collect();
list.push_all(new_list.as_slice());
fn toml_string(val: &toml::Value) -> CargoResult<String> {
match val {
&toml::String(ref str) => Ok(str.clone()),
- _ => Err(error(""))
+ _ => Err(internal(""))
}
}
} as Box<CargoError>
}
-pub fn error<S1: Str>(error: S1) -> Box<CargoError> {
+pub fn internal<S1: Str>(error: S1) -> Box<CargoError> {
box ConcreteCargoError {
description: error.as_slice().to_str(),
detail: None,
pub use self::process_builder::{process,ProcessBuilder};
pub use self::result::{Wrap, Require};
pub use self::errors::{CargoResult, CargoError, BoxError, ChainError, CliResult, CliError, ProcessError};
-pub use self::errors::{process_error, internal_error, error, human, chain};
+pub use self::errors::{process_error, internal_error, internal, human, chain};
pub use self::paths::realpath;
pub mod graph;
use core::{SourceId,GitKind};
use core::manifest::{LibKind,Lib};
use core::{Summary,Manifest,Target,Dependency,PackageId};
-use util::{CargoResult, Require, error, human};
+use util::{CargoResult, Require, 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 toml = try!(toml_to_manifest(root).map_err(|_| error("Cargo.toml is not a valid manifest")));
+ let root = try!(toml::parse_from_bytes(contents).map_err(|_| human("Cargo.toml is not valid Toml")));
+ let toml = try!(toml_to_manifest(root).map_err(|_| human("Cargo.toml is not a valid manifest")));
toml.to_manifest(source_id)
}