Skip to content

Commit 2903fa9

Browse files
authored
Merge pull request rust-lang#117 from JohnTitor/use-anyhow
Update `cargo` and `crates-io` dependencies
2 parents 3122410 + 249aa30 commit 2903fa9

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ name = "rust-semver-public"
2727
path = "src/bin/rust_semver_public.rs"
2828

2929
[dependencies]
30-
cargo = "0.42"
31-
crates-io = "0.30"
30+
cargo = "0.43"
31+
crates-io = "0.31"
3232
curl = "0.4.21"
3333
env_logger = "0.7"
34-
failure = "0.1"
34+
anyhow = "1.0.27"
3535
log = "0.4"
3636
rand = "0.7"
3737
semver = "0.9"

src/bin/cargo_semver.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ fn main() {
8181
let config_res = config.configure(
8282
0, // verbose
8383
quiet,
84-
&None, // color
84+
None, // color
8585
false, // frozen
8686
false, // locked
8787
matches.opt_present("offline"),
8888
&None, // target_dir
8989
&[], // unstable_flags
90+
&[], // cli_config
9091
);
9192

9293
if let Err(e) = config_res {
@@ -143,27 +144,27 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
143144
.arg("-")
144145
.stdin(Stdio::piped())
145146
.spawn()
146-
.map_err(|e| failure::err_msg(format!("could not spawn rustc: {}", e)))?;
147+
.map_err(|e| anyhow::Error::msg(format!("could not spawn rustc: {}", e)))?;
147148

148149
if let Some(ref mut stdin) = child.stdin {
149150
stdin.write_fmt(format_args!(
150151
"#[allow(unused_extern_crates)] \
151152
extern crate new;"
152153
))?;
153154
} else {
154-
return Err(failure::err_msg(
155+
return Err(anyhow::Error::msg(
155156
"could not pipe to rustc (wtf?)".to_owned(),
156157
));
157158
}
158159

159160
let exit_status = child
160161
.wait()
161-
.map_err(|e| failure::err_msg(format!("failed to wait for rustc: {}", e)))?;
162+
.map_err(|e| anyhow::Error::msg(format!("failed to wait for rustc: {}", e)))?;
162163

163164
return if exit_status.success() {
164165
Ok(())
165166
} else {
166-
Err(failure::err_msg("rustc-semver-public errored".to_owned()))
167+
Err(anyhow::Error::msg("rustc-semver-public errored".to_owned()))
167168
};
168169
}
169170

@@ -239,7 +240,7 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
239240

240241
let mut child = child
241242
.spawn()
242-
.map_err(|e| failure::err_msg(format!("could not spawn rustc: {}", e)))?;
243+
.map_err(|e| anyhow::Error::msg(format!("could not spawn rustc: {}", e)))?;
243244

244245
if let Some(ref mut stdin) = child.stdin {
245246
// The order of the `extern crate` declaration is important here: it will later
@@ -251,19 +252,19 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
251252
extern crate new;"
252253
))?;
253254
} else {
254-
return Err(failure::err_msg(
255+
return Err(anyhow::Error::msg(
255256
"could not pipe to rustc (wtf?)".to_owned(),
256257
));
257258
}
258259

259260
let exit_status = child
260261
.wait()
261-
.map_err(|e| failure::err_msg(format!("failed to wait for rustc: {}", e)))?;
262+
.map_err(|e| anyhow::Error::msg(format!("failed to wait for rustc: {}", e)))?;
262263

263264
if exit_status.success() {
264265
Ok(())
265266
} else {
266-
Err(failure::err_msg("rustc-semverver errored".to_owned()))
267+
Err(anyhow::Error::msg("rustc-semverver errored".to_owned()))
267268
}
268269
}
269270

@@ -353,21 +354,21 @@ mod cli {
353354
}
354355

355356
/// Validate CLI arguments
356-
pub fn validate_args(matches: &getopts::Matches) -> Result<(), failure::Error> {
357+
pub fn validate_args(matches: &getopts::Matches) -> Result<(), anyhow::Error> {
357358
if (matches.opt_present("s") && matches.opt_present("S"))
358359
|| matches.opt_count("s") > 1
359360
|| matches.opt_count("S") > 1
360361
{
361362
let msg = "at most one of `-s,--stable-path` and `-S,--stable-pkg` allowed";
362-
return Err(failure::err_msg(msg.to_owned()));
363+
return Err(anyhow::Error::msg(msg.to_owned()));
363364
}
364365

365366
if (matches.opt_present("c") && matches.opt_present("C"))
366367
|| matches.opt_count("c") > 1
367368
|| matches.opt_count("C") > 1
368369
{
369370
let msg = "at most one of `-c,--current-path` and `-C,--current-pkg` allowed";
370-
return Err(failure::err_msg(msg.to_owned()));
371+
return Err(anyhow::Error::msg(msg.to_owned()));
371372
}
372373

373374
Ok(())
@@ -386,7 +387,7 @@ mod cli {
386387
}
387388

388389
/// Exit with error `e`.
389-
pub fn exit_with_error(config: &cargo::Config, e: failure::Error) -> ! {
390+
pub fn exit_with_error(config: &cargo::Config, e: anyhow::Error) -> ! {
390391
config
391392
.shell()
392393
.set_verbosity(cargo::core::shell::Verbosity::Normal);
@@ -406,7 +407,7 @@ impl<'a> PackageNameAndVersion<'a> {
406407
/// Parses the string "name:version" into `Self`
407408
pub fn parse(s: &'a str) -> Result<Self> {
408409
let err = || {
409-
failure::err_msg(format!(
410+
anyhow::Error::msg(format!(
410411
"spec has to be of form `name:version` but is `{}`",
411412
s
412413
))
@@ -536,7 +537,7 @@ impl<'a> WorkInfo<'a> {
536537
}
537538
}
538539

539-
Err(failure::err_msg("lost build artifact".to_owned()))
540+
Err(anyhow::Error::msg("lost build artifact".to_owned()))
540541
}
541542
}
542543

@@ -552,7 +553,7 @@ pub fn find_on_crates_io(crate_name: &str) -> Result<crates_io::Crate> {
552553
registry
553554
.search(crate_name, 1)
554555
.map_err(|e| {
555-
failure::err_msg(format!(
556+
anyhow::Error::msg(format!(
556557
"failed to retrieve search results from the registry: {}",
557558
e
558559
))
@@ -562,7 +563,7 @@ pub fn find_on_crates_io(crate_name: &str) -> Result<crates_io::Crate> {
562563
.drain(..)
563564
.find(|krate| krate.name == crate_name)
564565
.ok_or_else(|| {
565-
failure::err_msg(format!("failed to find a matching crate `{}`", crate_name))
566+
anyhow::Error::msg(format!("failed to find a matching crate `{}`", crate_name))
566567
})
567568
})
568569
}

0 commit comments

Comments
 (0)