Skip to content

Commit 934ef6e

Browse files
committed
ErrorKind: replace Transient with Unexpected; replace most uses of Unavailable
1 parent c1c29f7 commit 934ef6e

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/error.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ use std::error::Error as stdError;
1818
/// Error kind which can be matched over.
1919
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
2020
pub enum ErrorKind {
21-
/// Permanent failure: likely not recoverable without user action.
21+
/// Feature is not available; not recoverable.
2222
Unavailable,
23-
/// Temporary failure: recommended to retry a few times, but may also be
24-
/// irrecoverable.
25-
Transient,
23+
/// Unexpected failure; there is a slim chance of recovery on retry.
24+
Unexpected,
2625
/// Not ready yet: recommended to try again a little later.
2726
NotReady,
2827
/// Uncategorised error
@@ -37,7 +36,7 @@ impl ErrorKind {
3736
/// See also `should_wait()`.
3837
pub fn should_retry(self) -> bool {
3938
match self {
40-
ErrorKind::Transient | ErrorKind::NotReady => true,
39+
ErrorKind::Unexpected | ErrorKind::NotReady => true,
4140
_ => false,
4241
}
4342
}
@@ -52,10 +51,10 @@ impl ErrorKind {
5251
/// A description of this error kind
5352
pub fn description(self) -> &'static str {
5453
match self {
55-
ErrorKind::Unavailable => "permanent failure or unavailable",
56-
ErrorKind::Transient => "transient failure",
54+
ErrorKind::Unavailable => "permanently unavailable",
55+
ErrorKind::Unexpected => "unexpected failure",
5756
ErrorKind::NotReady => "not ready yet",
58-
ErrorKind::Other => "uncategorised",
57+
ErrorKind::Other => "uncategorised error",
5958
ErrorKind::__Nonexhaustive => unreachable!(),
6059
}
6160
}

src/jitter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ impl ::std::error::Error for TimerError {
145145

146146
impl From<TimerError> for Error {
147147
fn from(err: TimerError) -> Error {
148+
// Timer check is already quite permissive of failures so we can assume
149+
// any errors reported are irrecoverable.
148150
Error::with_cause(ErrorKind::Unavailable,
149151
"timer jitter failed basic quality tests", err)
150152
}

src/os.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Rng for OsRng {
8383
}
8484

8585
match e.kind() {
86-
ErrorKind::Transient => {
86+
ErrorKind::Unexpected => {
8787
if !error_logged {
8888
warn!("OsRng failed; retrying up to {} times. Error: {:?}",
8989
TRANSIENT_RETRIES, e);
@@ -148,7 +148,7 @@ impl ReadRng {
148148
if (*guard).is_none() {
149149
info!("OsRng: opening random device {}", path.as_ref().display());
150150
let file = File::open(path).map_err(|err| Error::with_cause(
151-
ErrorKind::Unavailable,
151+
ErrorKind::Unexpected,
152152
"error opening random device",
153153
err
154154
))?;
@@ -169,7 +169,7 @@ impl ReadRng {
169169
let mut file = (*guard).as_mut().unwrap();
170170
// Use `std::io::read_exact`, which retries on `ErrorKind::Interrupted`.
171171
file.read_exact(dest).map_err(|err| {
172-
Error::with_cause(ErrorKind::Unavailable, "error reading random device", err)
172+
Error::with_cause(ErrorKind::Unexpected, "error reading random device", err)
173173
})
174174
}
175175
}
@@ -250,7 +250,7 @@ mod imp {
250250
));
251251
} else {
252252
return Err(Error::with_cause(
253-
ErrorKind::Unavailable,
253+
ErrorKind::Unexpected,
254254
"unexpected getrandom error",
255255
err,
256256
));
@@ -353,7 +353,7 @@ mod imp {
353353
// Cloudlibc provides its own `strerror` implementation so we
354354
// can use `from_raw_os_error` here.
355355
Err(Error::with_cause(
356-
ErrorKind::Unavailable,
356+
ErrorKind::Unexpected,
357357
"random_get() system call failed",
358358
io::Error::from_raw_os_error(errno),
359359
))
@@ -396,7 +396,7 @@ mod imp {
396396
};
397397
if ret == -1 {
398398
Err(Error::with_cause(
399-
ErrorKind::Unavailable,
399+
ErrorKind::Unexpected,
400400
"couldn't generate random bytes",
401401
io::Error::last_os_error()))
402402
} else {
@@ -434,7 +434,7 @@ mod imp {
434434
};
435435
if ret == -1 || s_len != s.len() {
436436
return Err(Error::with_cause(
437-
ErrorKind::Unavailable,
437+
ErrorKind::Unexpected,
438438
"kern.arandom sysctl failed",
439439
io::Error::last_os_error()));
440440
}
@@ -468,7 +468,7 @@ mod imp {
468468
};
469469
if ret == -1 {
470470
return Err(Error::with_cause(
471-
ErrorKind::Unavailable,
471+
ErrorKind::Unexpected,
472472
"getentropy failed",
473473
io::Error::last_os_error()));
474474
}
@@ -523,7 +523,7 @@ mod imp {
523523
Ok(actual) => filled += actual,
524524
Err(e) => {
525525
return Err(Error::with_cause(
526-
ErrorKind::Unavailable,
526+
ErrorKind::Unexpected,
527527
"cprng_draw failed",
528528
e));
529529
}
@@ -564,7 +564,7 @@ mod imp {
564564
};
565565
if ret == 0 {
566566
return Err(Error::with_cause(
567-
ErrorKind::Unavailable,
567+
ErrorKind::Unexpected,
568568
"couldn't generate random bytes",
569569
io::Error::last_os_error()));
570570
}

src/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<R: Read> Rng for ReadRng<R> {
6262
if dest.len() == 0 { return Ok(()); }
6363
// Use `std::io::read_exact`, which retries on `ErrorKind::Interrupted`.
6464
self.reader.read_exact(dest).map_err(|err| {
65-
Error::with_cause(ErrorKind::Unavailable, "ReadRng: read error", err)
65+
Error::with_cause(ErrorKind::Unexpected, "ReadRng: read error", err)
6666
})
6767
}
6868
}

0 commit comments

Comments
 (0)