diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs index 1d16de2a2fe..20346449fd1 100644 --- a/src/rustbook/book.rs +++ b/src/rustbook/book.rs @@ -124,7 +124,7 @@ pub fn parse_summary(input: R, src: &Path) -> Result p, None => { - errors.push(format!("Paths in SUMMARY.md must be relative, \ + errors.push(format!("paths in SUMMARY.md must be relative, \ but path '{}' for section '{}' is not.", given_path.unwrap(), title)); Path::new("") @@ -148,8 +148,9 @@ pub fn parse_summary(input: R, src: &Path) -> Result stack.len() + 1 { - // FIXME: better error message - errors.push(format!("Section '{}' is indented too many levels.", item.title)); + errors.push(format!("section '{}' is indented too deeply; \ + found {}, expected {} or less", + item.title, level, stack.len() + 1)); } else if level <= stack.len() { collapse(&mut stack, &mut top_items, level); } diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index 1cb5e38e190..44b1630d9fb 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -73,10 +73,7 @@ fn write_toc(book: &Book, path_to_root: &Path, out: &mut Writer) -> IoResult<()> } fn render(book: &Book, tgt: &Path) -> CliResult<()> { - let tmp = TempDir::new("rust-book") - .ok() - // FIXME: lift to Result instead - .expect("could not create temporary directory"); + let tmp = try!(TempDir::new("rust-book")); for (section, item) in book.iter() { println!("{} {}", section, item.title); @@ -163,30 +160,24 @@ impl Subcommand for Build { tgt = Path::new(os::args()[3].clone()); } - let _ = fs::mkdir(&tgt, io::USER_DIR); // FIXME: handle errors + try!(fs::mkdir(&tgt, io::USER_DIR)); - // FIXME: handle errors - let _ = File::create(&tgt.join("rust-book.css")).write_str(css::STYLE); + try!(File::create(&tgt.join("rust-book.css")).write_str(css::STYLE)); - let summary = File::open(&src.join("SUMMARY.md")); + let summary = try!(File::open(&src.join("SUMMARY.md"))); match book::parse_summary(summary, &src) { Ok(book) => { // execute rustdoc on the whole book - try!(render(&book, &tgt).map_err(|err| { - term.err(&format!("error: {}", err.description())[]); - err.detail().map(|detail| { - term.err(&format!("detail: {}", detail)[]); - }); - err - })) + render(&book, &tgt) } Err(errors) => { + let n = errors.len(); for err in errors.into_iter() { - term.err(&err[]); + term.err(&format!("error: {}", err)[]); } + + Err(box format!("{} errors occurred", n) as Box) } } - - Ok(()) // lol } } diff --git a/src/rustbook/error.rs b/src/rustbook/error.rs index a5915ed4d73..7d5e7efcc94 100644 --- a/src/rustbook/error.rs +++ b/src/rustbook/error.rs @@ -79,4 +79,5 @@ impl Error for IoError { } } + //fn iter_map_err>>(iter: I, diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index acb4edb7a45..48dad14321a 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -54,7 +54,12 @@ fn main() { Ok(_) => { match subcmd.execute(&mut term) { Ok(_) => (), - Err(_) => os::set_exit_status(-1), + Err(err) => { + term.err(&format!("error: {}", err.description())[]); + err.detail().map(|detail| { + term.err(&format!("detail: {}", detail)[]); + }); + } } } Err(err) => {