mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-09 13:39:46 -05:00
overhaul error messages
Inspired by the poor error message here: https://github.com/scottlamb/moonfire-nvr/issues/107#issuecomment-777587727 * print the friendlier Display version of the error rather than Debug. Eg, "EROFS: Read-only filesystem" rather than "Sys(EROFS)". Do this everywhere: on command exit, on syncer retries, and on stream retries. * print the most immediate problem and additional lines for each cause. * print the backtrace or an advertisement for RUST_BACKTRACE=1 if it's unavailable. * also mention RUST_BACKTRACE=1 in the troubleshooting guide. * add context in various places, including pathnames. There are surely many places more it'd be helpful, but this is a start. * allow subcommands to return failure without an Error. In particular, "moonfire-nvr check" does its own error printing because it wants to print all the errors it finds. Printing "see earlier errors" with a meaningless stack trace seems like it'd just confuse. But I also want to get rid of the misleading "Success" at the end and 0 return to the OS.
This commit is contained in:
@@ -64,7 +64,7 @@ where C: Clocks, E: Into<Error> {
|
||||
Err(e) => e.into(),
|
||||
};
|
||||
let sleep_time = Duration::seconds(1);
|
||||
warn!("sleeping for {:?} after error: {:?}", sleep_time, e);
|
||||
warn!("sleeping for {:?} after error: {}", sleep_time, crate::error::prettify_failure(&e));
|
||||
clocks.sleep(sleep_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,22 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
/// Returns a pretty-and-informative version of `e`.
|
||||
pub fn prettify_failure(e: &failure::Error) -> String {
|
||||
let mut msg = e.to_string();
|
||||
for cause in e.iter_causes() {
|
||||
write!(&mut msg, "caused by: {}", cause).unwrap();
|
||||
}
|
||||
if e.backtrace().is_empty() {
|
||||
write!(&mut msg, "\n(set environment variable RUST_BACKTRACE=1 to see backtraces)")
|
||||
.unwrap();
|
||||
} else {
|
||||
write!(&mut msg, "\nBacktrace:\n{}", e.backtrace()).unwrap();
|
||||
}
|
||||
msg
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
|
||||
@@ -33,4 +33,4 @@ pub mod time;
|
||||
mod error;
|
||||
pub mod strutil;
|
||||
|
||||
pub use crate::error::{Error, ErrorKind, ResultExt};
|
||||
pub use crate::error::{Error, ErrorKind, ResultExt, prettify_failure};
|
||||
|
||||
Reference in New Issue
Block a user