Squelch warnings and minor cleanup

This commit is contained in:
Yehuda Katz 2014-06-19 01:21:24 -07:00
parent 3e09f70259
commit 8c72add4f5
13 changed files with 27 additions and 25 deletions

View File

@ -25,7 +25,7 @@ fn execute(options: Options) -> CliResult<Option<Package>> {
let source_id = SourceId::for_path(&Path::new(options.manifest_path.as_slice()));
let mut source = PathSource::new(&source_id);
try!(source.update().map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1)));
try!(source.update().map_err(|err| CliError::new(err.description(), 1)));
source
.get_root_package()

View File

@ -13,7 +13,7 @@ use std::io::process::{Command,InheritFd,ExitStatus,ExitSignal};
use serialize::Encodable;
use cargo::{NoFlags,execute_main_without_stdin,handle_error};
use cargo::util::important_paths::find_project;
use cargo::util::{CliError, CliResult, CargoResult, CargoError, Require, config, box_error};
use cargo::util::{CliError, CliResult, Require, config};
fn main() {
execute();
@ -91,7 +91,7 @@ impl FlagConfig for ConfigForKeyFlags {
}
fn config_for_key(args: ConfigForKeyFlags) -> CliResult<Option<ConfigOut>> {
let value = try!(config::get_config(os::getcwd(), args.key.as_slice()).map_err(|err|
let value = try!(config::get_config(os::getcwd(), args.key.as_slice()).map_err(|_|
CliError::new("Couldn't load configuration", 1)));
if args.human {
@ -116,7 +116,7 @@ impl FlagConfig for ConfigListFlags {
}
fn config_list(args: ConfigListFlags) -> CliResult<Option<ConfigOut>> {
let configs = try!(config::all_configs(os::getcwd()).map_err(|e|
let configs = try!(config::all_configs(os::getcwd()).map_err(|_|
CliError::new("Couldn't load configuration", 1)));
if args.human {

View File

@ -10,7 +10,7 @@ use core::{
Summary
};
use core::dependency::SerializedDependency;
use util::{CargoResult, CargoError, box_error};
use util::{CargoResult, box_error};
#[deriving(PartialEq,Clone)]
pub struct Manifest {

View File

@ -101,10 +101,10 @@ fn flags_from_args<T: RepresentsFlags>() -> CliResult<T> {
fn json_from_stdin<T: RepresentsJSON>() -> CliResult<T> {
let mut reader = io::stdin();
let input = try!(reader.read_to_str().map_err(|e| CliError::new("Standard in did not exist or was not UTF-8", 1)));
let input = try!(reader.read_to_str().map_err(|_| CliError::new("Standard in did not exist or was not UTF-8", 1)));
let json = try!(json::from_str(input.as_slice()).map_err(|e| CliError::new("Could not parse standard in as JSON", 1)));
let json = try!(json::from_str(input.as_slice()).map_err(|_| CliError::new("Could not parse standard in as JSON", 1)));
let mut decoder = json::Decoder::new(json);
Decodable::decode(&mut decoder).map_err(|e: json::DecoderError| CliError::new("Could not process standard in as input", 1))
Decodable::decode(&mut decoder).map_err(|_| CliError::new("Could not process standard in as input", 1))
}

View File

@ -1,7 +1,7 @@
use std::io::File;
use util;
use core::{Package,Manifest,SourceId};
use util::{CargoResult, CargoError, box_error, human};
use util::{CargoResult, box_error, human};
pub fn read_manifest(contents: &[u8], source_id: &SourceId) -> CargoResult<(Manifest, Vec<Path>)> {
util::toml::to_manifest(contents, source_id).map_err(human)

View File

@ -1,10 +1,9 @@
use std::os::args;
use std::io;
use std::path::Path;
use std::str;
use core::{Package,PackageSet,Target};
use util;
use util::{CargoResult, CargoError, ProcessBuilder, error, human, box_error};
use util::{CargoResult, CargoError, ProcessBuilder, error, human};
type Args = Vec<String>;
@ -60,7 +59,7 @@ fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool)
let rustc = prepare_rustc(root, target, *crate_type, dest, deps);
try!((if verbose {
try!(if verbose {
rustc.exec().map_err(|err| {
log!(5, "exec failed; error={}", err.description());
human(err)
@ -70,7 +69,7 @@ fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool)
log!(5, "exec_with_output failed; error={}", err.description());
human(err)
})
}));
});
}
Ok(())

View File

@ -226,11 +226,11 @@ impl GitCheckout {
fn clone_repo(&self) -> CargoResult<()> {
let dirname = Path::new(self.location.dirname());
try!(mkdir_recursive(&dirname, UserDir).map_err(|e|
try!(mkdir_recursive(&dirname, UserDir).map_err(|_|
box_error(format!("Couldn't mkdir {}", Path::new(self.location.dirname()).display()))));
if self.location.exists() {
try!(rmdir_recursive(&self.location).map_err(|e|
try!(rmdir_recursive(&self.location).map_err(|_|
box_error(format!("Couldn't rmdir {}", Path::new(&self.location).display()))));
}
@ -267,7 +267,7 @@ fn git_inherit(path: &Path, str: String) -> CargoResult<()> {
}
fn git_output(path: &Path, str: String) -> CargoResult<String> {
let output = try!(git(path, str.as_slice()).exec_with_output().map_err(|err|
let output = try!(git(path, str.as_slice()).exec_with_output().map_err(|_|
box_error(format!("Executing `git {}` failed", str))));
Ok(to_str(output.output.as_slice()).as_slice().trim_right().to_str())

View File

@ -40,7 +40,7 @@ impl PathSource {
log!(5, "get_root_package; source={}", self);
if !self.updated {
return Err(simple_human("source has not been updated"))
return Err(box_error("source has not been updated"))
}
match self.packages.as_slice().head() {

View File

@ -21,6 +21,7 @@ pub trait CargoError {
}
}
impl Show for Box<CargoError> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
try!(write!(f, "{}", self.description()));
@ -67,6 +68,7 @@ impl CargoError for TomlError {
}
pub struct ProcessError {
pub msg: String,
pub command: String,
pub exit: Option<ProcessExit>,
pub output: Option<ProcessOutput>,
@ -90,7 +92,7 @@ impl CargoError for ProcessError {
Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(),
None => "never executed".to_str()
};
format!("Executing `{}` failed (status={})", self.command, exit)
format!("{} (status={})", self.msg, exit)
}
fn detail(&self) -> Option<String> {
@ -102,7 +104,7 @@ impl CargoError for ProcessError {
}
}
struct ConcreteCargoError {
pub struct ConcreteCargoError {
description: String,
detail: Option<String>,
cause: Option<Box<CargoError>>,
@ -160,6 +162,7 @@ impl CliError {
pub fn process_error<S: Str>(msg: S, command: &Command, 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()),

View File

@ -3,7 +3,7 @@ use std::fmt::{Show,Formatter};
use std::os;
use std::path::Path;
use std::io::process::{Command,ProcessOutput,InheritFd};
use util::{CargoResult, CargoError, ProcessError, process_error, box_error};
use util::{ProcessError, process_error};
use std::collections::HashMap;
#[deriving(Clone,PartialEq)]
@ -74,7 +74,7 @@ impl ProcessBuilder {
let msg = || format!("Could not execute process `{}`", self.debug_string());
let exit = try!(command.status().map_err(|e| process_error(msg(), &command, None, None)));
let exit = try!(command.status().map_err(|_| process_error(msg(), &command, None, None)));
if exit.success() {
Ok(())
@ -89,7 +89,7 @@ impl ProcessBuilder {
let msg = || format!("Could not execute process `{}`", self.debug_string());
let output = try!(command.output().map_err(|e| process_error(msg(), &command, None, None)));
let output = try!(command.output().map_err(|_| process_error(msg(), &command, None, None)));
if output.status.success() {
Ok(output)

View File

@ -10,7 +10,7 @@ use std::vec::Vec;
use std::fmt::Show;
use ham = hamcrest;
use cargo::core::shell;
use cargo::util::{process,ProcessBuilder,CargoError};
use cargo::util::{process,ProcessBuilder};
use cargo::util::ProcessError;
pub mod paths;

View File

@ -64,7 +64,7 @@ test!(cargo_compile_with_invalid_code {
assert_that(p.cargo_process("cargo-compile"),
execs()
.with_status(101)
.with_stderr(format!("src/foo.rs:1:1: 1:8 error: expected item but found `invalid`\nsrc/foo.rs:1 invalid rust code!\n ^~~~~~~\nExecuting `rustc 'src/foo.rs' '--crate-type' 'bin' '--out-dir' '{}' '-L' '{}'` failed (status=101)", target.display(), target.join("deps").display()).as_slice()));
.with_stderr(format!("src/foo.rs:1:1: 1:8 error: expected item but found `invalid`\nsrc/foo.rs:1 invalid rust code!\n ^~~~~~~\nCould not execute process `rustc src/foo.rs --crate-type bin --out-dir {} -L {}` (status=101)", target.display(), target.join("deps").display()).as_slice()));
})
test!(cargo_compile_with_warnings_in_the_root_package {

View File

@ -3,7 +3,7 @@ use std::io::File;
use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
use hamcrest::{assert_that,existing_file};
use cargo;
use cargo::util::{CargoResult, ProcessError, process};
use cargo::util::{ProcessError, process};
fn setup() {
}