hashglobe: Dump more information if out of memory while allocating a table.

Sometimes, we got a crash message:
"called `Result::unwrap()` on an `Err` value: FailedAllocationError {
reason: "out of memory when allocating RawTable" }" on stylo, but
this is not enough to debug, so let's add one more field in
FailedAllocationError, so we can know the size we are allocating.
This commit is contained in:
Boris Chiou 2017-12-06 16:18:19 +08:00
parent b24778202a
commit cfe6451d8e
2 changed files with 15 additions and 10 deletions

View file

@ -29,12 +29,14 @@ trait Recover<Q: ?Sized> {
#[derive(Debug)]
pub struct FailedAllocationError {
reason: &'static str,
/// The size we are allocating, if needed.
allocation_size: Option<usize>,
}
impl FailedAllocationError {
#[inline]
pub fn new(reason: &'static str) -> Self {
Self { reason }
Self { reason, allocation_size: None }
}
}
@ -46,6 +48,9 @@ impl error::Error for FailedAllocationError {
impl fmt::Display for FailedAllocationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.reason.fmt(f)
match self.allocation_size {
Some(size) => write!(f, "{}, allocation size: {}", self.reason, size),
None => self.reason.fmt(f),
}
}
}