Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log error details via Display instead of Debug #249

Merged
merged 3 commits into from
Feb 17, 2018
Merged
Changes from 1 commit
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
Next Next commit
Log error details via Display instead of Debug
dhardy committed Jan 31, 2018
commit cd72f26be1c88013945bbe7181e7d5275e078d60
10 changes: 9 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ impl ErrorKind {
/// A description of this error kind
pub fn description(self) -> &'static str {
match self {
ErrorKind::Unavailable => "permanent failure or unavailable",
ErrorKind::Unavailable => "permanent failure",
ErrorKind::Transient => "transient failure",
ErrorKind::NotReady => "not ready yet",
ErrorKind::Other => "uncategorised",
@@ -123,6 +123,14 @@ impl Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[cfg(feature="std")] {
if let Some(ref cause) = self.cause {
return write!(f, "RNG error [{}]: {}; cause: {}",
self.kind.description(),
self.msg(),
cause);
}
}
write!(f, "RNG error [{}]: {}", self.kind.description(), self.msg())
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -856,9 +856,9 @@ impl<R: SeedableRng> NewRng for R {

trace!("Seeding new RNG");
new_os().or_else(|e1| {
warn!("OsRng failed [falling back to JitterRng]: {:?}", e1);
warn!("OsRng failed [falling back to JitterRng]: {}", e1);
new_jitter().map_err(|_e2| {
warn!("JitterRng failed: {:?}", _e2);
warn!("JitterRng failed: {}", _e2);
// TODO: can we somehow return both error sources?
Error::with_cause(
ErrorKind::Unavailable,
2 changes: 1 addition & 1 deletion src/os.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ impl Rng for OsRng {
loop {
if let Err(e) = self.try_fill_bytes(dest) {
if log_err == 0 {
warn!("OsRng failed: {:?}", e);
warn!("OsRng failed: {}", e);
}

if e.kind().should_retry() {