mononoke: add context to alias deserialize error handling

Summary: Add context to show the affected key if there are problems deserializing an alias.

Reviewed By: krallin

Differential Revision: D22629544

fbshipit-source-id: 1718d4187386e37038bb5c958db2659bd5b54cfd
This commit is contained in:
Alex Hornby 2020-07-21 06:10:33 -07:00 committed by Facebook GitHub Bot
parent fb18541328
commit 2aaddc487e
2 changed files with 6 additions and 3 deletions

View File

@ -5,11 +5,11 @@
* GNU General Public License version 2.
*/
use anyhow::Error;
use anyhow::{Context, Error};
use blobstore::{Blobstore, Loadable, LoadableError, Storable};
use context::CoreContext;
use futures::future::{self, BoxFuture, FutureExt};
use mononoke_types::{hash, ContentAlias, ContentId};
use mononoke_types::{errors::ErrorKind, hash, ContentAlias, ContentId};
/// Key for fetching - we can access with any of the supported key types
#[derive(Debug, Clone)]
@ -92,10 +92,11 @@ impl Loadable for Alias {
let get = blobstore.get(ctx, key.clone());
async move {
let maybe_alias = get.await?;
let blob = maybe_alias.ok_or(LoadableError::Missing(key))?;
let blob = maybe_alias.ok_or_else(|| LoadableError::Missing(key.clone()))?;
ContentAlias::from_bytes(blob.into_raw_bytes())
.map(|alias| alias.content_id())
.with_context(|| ErrorKind::BlobKeyError(key.clone()))
.map_err(LoadableError::Error)
}
.boxed()

View File

@ -24,6 +24,8 @@ pub enum ErrorKind {
InvalidMPath(MPath, String),
#[error("error while deserializing blob for '{0}'")]
BlobDeserializeError(String),
#[error("error for key '{0}'")]
BlobKeyError(String),
#[error("invalid Thrift structure '{0}': {1}")]
InvalidThrift(String, String),
#[error("invalid changeset date: {0}")]