Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.

A couple small error handling improvements. #233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use clap::{App, Arg, ArgMatches, SubCommand};

use rustdoc::{build, error, Config, Result, Verbosity};

use std::io::{stderr, Write};
use std::process;
use std::path::PathBuf;

Expand Down Expand Up @@ -310,16 +309,16 @@ fn check_unimplemented_flags(matches: &ArgMatches) {

fn main() {
if let Err(e) = run() {
let stderr = &mut stderr();
let errmsg = "Error writing to stderr";
eprintln!("Error: {}", e);

writeln!(stderr, "Error: {}", e).expect(errmsg);

writeln!(stderr, "Caused by: {}", e.cause()).expect(errmsg);
eprintln!("Caused by: {}", e.cause());

// The backtrace is not always generated. Try to run this example
// with `RUST_BACKTRACE=1`.
writeln!(stderr, "Backtrace, if any: {:?}", e.backtrace()).expect(errmsg);
let backtrace = e.backtrace().to_string();
if !backtrace.is_empty() {
eprintln!("Backtrace: {:?}", backtrace);
}

process::exit(1);
}
Expand Down