aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen.rs
diff options
context:
space:
mode:
authorPascal Hertleif <[email protected]>2019-11-13 19:51:57 +0000
committerPascal Hertleif <[email protected]>2019-11-13 19:51:57 +0000
commit5075c77957e127be51e1b5271567f906abeb50c6 (patch)
treec8e8d8f29011ad2b2472a201561f3f3dc1627d8f /xtask/src/codegen.rs
parent5e3c1c2b5f63e57f98a7d02f75a559d225341b1c (diff)
Use anyhow::Result in xtask, add contexts
This builds on #2231 but was actually done before that. You see, the cause for #2231 was that I got this error message: Error: Error { kind: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" }) } Just switching to `anyhow::Result` got me stack traces (when setting `RUST_LIB_BACKTRACE=1`) that at least showed stack backtrace: 0: std::backtrace::Backtrace::create 1: std::backtrace::Backtrace::capture 2: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from 3: xtask::install_server 4: xtask::install 5: xtask::main 6: std::rt::lang_start::{{closure}} 7: std::panicking::try::do_call 8: __rust_maybe_catch_panic 9: std::rt::lang_start_internal 10: std::rt::lang_start 11: main With the added contexts (not at all exhaustive), the error became Error: install server Caused by: 0: build AutoCfg with target directory 1: No such file or directory (os error 2) Since anyhow is such a small thing (no new transitive dependencies!), and in general gives you `Result<T, Box<dyn Error>>` on steroids, I think this a nice small change. The only slightly annoying thing was to replace all the `Err(format!(…))?` calls (haven't even looked at whether we can make it support wrapping strings though), but the `bail!` macro is shorter anyway :)
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r--xtask/src/codegen.rs8
1 files changed, 3 insertions, 5 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 770b55a9a..53f524f42 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -52,7 +52,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
52 _ => (), 52 _ => (),
53 } 53 }
54 if mode == Mode::Verify { 54 if mode == Mode::Verify {
55 Err(format!("`{}` is not up-to-date", path.display()))?; 55 anyhow::bail!("`{}` is not up-to-date", path.display());
56 } 56 }
57 eprintln!("updating {}", path.display()); 57 eprintln!("updating {}", path.display());
58 fs::write(path, contents)?; 58 fs::write(path, contents)?;
@@ -101,10 +101,8 @@ fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) ->
101 let is_comment = line.starts_with(prefix); 101 let is_comment = line.starts_with(prefix);
102 if is_comment { 102 if is_comment {
103 block.push(line[prefix.len()..].to_string()); 103 block.push(line[prefix.len()..].to_string());
104 } else { 104 } else if !block.is_empty() {
105 if !block.is_empty() { 105 res.push(mem::replace(&mut block, Vec::new()));
106 res.push(mem::replace(&mut block, Vec::new()))
107 }
108 } 106 }
109 } 107 }
110 if !block.is_empty() { 108 if !block.is_empty() {