Convert thrift to failure

Summary: Migrate `rust-thrift` from `error-chain` to `failure`.

Reviewed By: Imxset21

Differential Revision: D13853559

fbshipit-source-id: 4bab8c544588265c85dee2f668ed47b8e97d321e
This commit is contained in:
Zeyi Fan 2019-02-06 10:11:07 -08:00 committed by Facebook Github Bot
parent 44b06df35f
commit ef0272abca
8 changed files with 14 additions and 27 deletions

View File

@ -5,6 +5,7 @@
// GNU General Public License version 2 or any later version.
extern crate apiserver_thrift;
extern crate failure_ext;
extern crate futures_ext;
extern crate srclient;
@ -26,7 +27,7 @@ pub struct MononokeAPIClient {
}
impl MononokeAPIClient {
pub fn new_with_tier_repo(tier: &str, repo: &str) -> Result<Self, srclient::errors::Error> {
pub fn new_with_tier_repo(tier: &str, repo: &str) -> Result<Self, failure_ext::Error> {
let inner =
SRChannelBuilder::from_service_name(tier)?.build_client(make_MononokeAPIService)?;
@ -41,7 +42,7 @@ impl MononokeAPIClient {
revision: String,
path: String,
bookmark: bool,
) -> BoxFuture<Vec<u8>, apiserver_thrift::errors::Error> {
) -> BoxFuture<Vec<u8>, failure_ext::Error> {
let rev = if bookmark {
MononokeRevision::bookmark(revision)
} else {
@ -58,14 +59,14 @@ impl MononokeAPIClient {
pub fn get_changeset(
&self,
revision: String,
) -> BoxFuture<MononokeChangeset, apiserver_thrift::errors::Error> {
) -> BoxFuture<MononokeChangeset, failure_ext::Error> {
self.inner.get_changeset(&MononokeGetChangesetParams {
repo: self.repo.clone(),
revision: MononokeRevision::commit_hash(revision),
})
}
pub fn get_branches(&self) -> BoxFuture<MononokeBranches, apiserver_thrift::errors::Error> {
pub fn get_branches(&self) -> BoxFuture<MononokeBranches, failure_ext::Error> {
self.inner.get_branches(&MononokeGetBranchesParams {
repo: self.repo.clone(),
})
@ -75,7 +76,7 @@ impl MononokeAPIClient {
&self,
revision: String,
path: String,
) -> BoxFuture<MononokeDirectory, apiserver_thrift::errors::Error> {
) -> BoxFuture<MononokeDirectory, failure_ext::Error> {
self.inner.list_directory(&MononokeListDirectoryParams {
repo: self.repo.clone(),
revision: MononokeRevision::commit_hash(revision),

View File

@ -40,7 +40,6 @@ use std::collections::{HashMap, HashSet};
use std::result;
use bytes::Bytes;
use failure::SyncFailure;
use sql::{Connection, Transaction};
pub use sql_ext::SqlConstructors;
@ -119,7 +118,7 @@ pub fn serialize_cs_entries(cs_entries: Vec<ChangesetEntry>) -> Bytes {
pub fn deserialize_cs_entries(blob: &Bytes) -> Result<Vec<ChangesetEntry>> {
let thrift_entries: Vec<changeset_entry_thrift::ChangesetEntry> =
compact_protocol::deserialize(blob).map_err(SyncFailure::new)?;
compact_protocol::deserialize(blob)?;
let mut entries = vec![];
for thrift_entry in thrift_entries {
let parents: Result<Vec<_>> = thrift_entry

View File

@ -9,7 +9,7 @@
use std::fmt;
use bytes::Bytes;
use failure::{chain::*, err_msg, SyncFailure};
use failure::{chain::*, err_msg};
use quickcheck::{empty_shrinker, Arbitrary, Gen};
use rust_thrift::compact_protocol;
@ -75,9 +75,7 @@ impl HgChangesetEnvelope {
}
pub fn from_blob(blob: HgEnvelopeBlob) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(blob.0.as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError(
"HgChangesetEnvelope".into(),
))?;

View File

@ -9,7 +9,7 @@
use std::fmt;
use bytes::Bytes;
use failure::{chain::*, err_msg, SyncFailure};
use failure::{chain::*, err_msg};
use quickcheck::{empty_shrinker, Arbitrary, Gen};
use rust_thrift::compact_protocol;
@ -83,9 +83,7 @@ impl HgFileEnvelope {
}
pub fn from_blob(blob: HgEnvelopeBlob) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(blob.0.as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError("HgFileEnvelope".into()))?;
Self::from_thrift(thrift_tc)
}

View File

@ -9,7 +9,7 @@
use std::fmt;
use bytes::Bytes;
use failure::{chain::*, err_msg, SyncFailure};
use failure::{chain::*, err_msg};
use quickcheck::{empty_shrinker, Arbitrary, Gen};
use rust_thrift::compact_protocol;
@ -78,9 +78,7 @@ impl HgManifestEnvelope {
}
pub fn from_blob(blob: HgEnvelopeBlob) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(blob.0.as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError("HgManifestEnvelope".into()))?;
Self::from_thrift(thrift_tc)
}

View File

@ -6,7 +6,7 @@
use std::collections::BTreeMap;
use failure::{chain::*, err_msg, SyncFailure};
use failure::{chain::*, err_msg};
use quickcheck::{Arbitrary, Gen};
use rust_thrift::compact_protocol;
@ -219,9 +219,7 @@ impl BlobstoreValue for BonsaiChangeset {
}
fn from_blob(blob: Blob<Self::Key>) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(blob.data().as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError("BonsaiChangeset".into()))?;
Self::from_thrift(thrift_tc)
}

View File

@ -7,7 +7,7 @@
use std::fmt::{self, Debug};
use bytes::Bytes;
use failure::{chain::*, SyncFailure};
use failure::chain::*;
use quickcheck::{single_shrinker, Arbitrary, Gen};
use rust_thrift::compact_protocol;
@ -73,9 +73,7 @@ impl FileContents {
}
pub fn from_encoded_bytes(encoded_bytes: Bytes) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(encoded_bytes.as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError("FileContents".into()))?;
Self::from_thrift(thrift_tc)
}
@ -94,9 +92,7 @@ impl BlobstoreValue for FileContents {
}
fn from_blob(blob: ContentBlob) -> Result<Self> {
// TODO (T27336549) stop using SyncFailure once thrift is converted to failure
let thrift_tc = compact_protocol::deserialize(blob.data().as_ref())
.map_err(SyncFailure::new)
.chain_err(ErrorKind::BlobDeserializeError("FileContents".into()))?;
Self::from_thrift(thrift_tc)
}

View File

@ -11,7 +11,7 @@ use bytes::Bytes;
use chashmap::CHashMap;
use cloned::cloned;
use context::CoreContext;
use failure_ext::{Error, Result, SyncFailure};
use failure_ext::{Error, Result};
use futures::future::{join_all, ok, Future};
use futures::future::{loop_fn, Loop};
use futures_ext::{BoxFuture, FutureExt};
@ -105,8 +105,7 @@ impl SkiplistNodeType {
}
pub fn deserialize_skiplist_map(bytes: Bytes) -> Result<HashMap<ChangesetId, SkiplistNodeType>> {
let map: HashMap<_, skiplist_thrift::SkiplistNodeType> =
compact_protocol::deserialize(&bytes).map_err(SyncFailure::new)?;
let map: HashMap<_, skiplist_thrift::SkiplistNodeType> = compact_protocol::deserialize(&bytes)?;
let v: Result<Vec<_>> = map
.into_iter()