Skip to content

Commit 9fe7f07

Browse files
committed
Auto merge of #3991 - alexcrichton:better-errors, r=matklad
Improve configuration load errors Add some more context information on the backtrace
2 parents de52ccd + 1db53b7 commit 9fe7f07

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/cargo/util/config.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ impl Config {
394394

395395
walk_tree(&self.cwd, |mut file, path| {
396396
let mut contents = String::new();
397-
file.read_to_string(&mut contents)?;
397+
file.read_to_string(&mut contents).chain_error(|| {
398+
human(format!("failed to read configuration file `{}`",
399+
path.display()))
400+
})?;
398401
let toml = cargo_toml::parse(&contents,
399402
&path,
400403
self).chain_error(|| {
@@ -405,7 +408,10 @@ impl Config {
405408
human(format!("failed to load TOML configuration from `{}`",
406409
path.display()))
407410
})?;
408-
cfg.merge(value)?;
411+
cfg.merge(value).chain_error(|| {
412+
human(format!("failed to merge configuration at `{}`",
413+
path.display()))
414+
})?;
409415
Ok(())
410416
}).chain_error(|| human("Couldn't load Cargo configuration"))?;
411417

tests/bad-config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ fn bad5() {
120120
Caused by:
121121
Couldn't load Cargo configuration
122122
123+
Caused by:
124+
failed to merge configuration at `[..]`
125+
123126
Caused by:
124127
failed to merge key `foo` between files:
125128
file 1: [..]foo[..]foo[..]config

0 commit comments

Comments
 (0)