mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
common/rust: Remove E argument of with_context closure
Summary: As evidenced by the fact that it is not used anywhere, this argument is not useful. Before: ``` .with_context(|_| format!(...)) ``` After: ``` .with_context(|| format!(...)) ``` In the case that someone in the future does need a reference to the error value in a context, the recommended way to write would be: ``` .map_err(|e| { /* whatever you want to do with &e */ e.context(format!(...)) }) ``` This diff is in preparation for migrating off of failure::Fail to std::error::Error for error types, in combination with anyhow::Error whose [with_context closure does not take an argument](https://docs.rs/anyhow/1.0.19/anyhow/trait.Context.html). Reviewed By: Imxset21 Differential Revision: D18498898 fbshipit-source-id: 2c6f1929944d5877c408e367cde3c99ab2a5a07a
This commit is contained in:
parent
231803d648
commit
d61b13ecc2
@ -56,7 +56,7 @@ struct ParseChangeset {
|
||||
fn parse_changeset(revlog_repo: RevlogRepo, csid: HgChangesetId) -> ParseChangeset {
|
||||
let revlogcs = revlog_repo
|
||||
.get_changeset(csid)
|
||||
.with_context(move |_| format!("While reading changeset {:?}", csid))
|
||||
.with_context(move || format!("While reading changeset {:?}", csid))
|
||||
.map_err(Fail::compat)
|
||||
.boxify()
|
||||
.shared();
|
||||
@ -80,7 +80,7 @@ fn parse_changeset(revlog_repo: RevlogRepo, csid: HgChangesetId) -> ParseChanges
|
||||
}
|
||||
}
|
||||
})
|
||||
.with_context(move |_| format!("While reading root manifest for {:?}", csid))
|
||||
.with_context(move || format!("While reading root manifest for {:?}", csid))
|
||||
.map_err(Fail::compat)
|
||||
.boxify()
|
||||
.shared();
|
||||
@ -116,7 +116,7 @@ fn parse_changeset(revlog_repo: RevlogRepo, csid: HgChangesetId) -> ParseChanges
|
||||
let p2 = parents.next().unwrap_or(Ok(None).into_future().boxify());
|
||||
|
||||
p1.join(p2)
|
||||
.with_context(move |_| format!("While reading parents of {:?}", csid))
|
||||
.with_context(move || format!("While reading parents of {:?}", csid))
|
||||
.from_err()
|
||||
}
|
||||
})
|
||||
@ -128,7 +128,7 @@ fn parse_changeset(revlog_repo: RevlogRepo, csid: HgChangesetId) -> ParseChanges
|
||||
}
|
||||
})
|
||||
.flatten_stream()
|
||||
.with_context(move |_| format!("While reading entries for {:?}", csid))
|
||||
.with_context(move || format!("While reading entries for {:?}", csid))
|
||||
.from_err()
|
||||
.boxify();
|
||||
|
||||
@ -472,7 +472,7 @@ impl UploadChangesets {
|
||||
// We know they are public.
|
||||
oneshot::spawn(cshandle
|
||||
.get_completed_changeset()
|
||||
.with_context(move |_| format!("While uploading changeset: {}", csid))
|
||||
.with_context(move || format!("While uploading changeset: {}", csid))
|
||||
.from_err(), &executor)
|
||||
.and_then(move |shared| phases_store.add_reachable_as_public(ctx, blobrepo, vec![shared.0.get_changeset_id()]).map(move |_| shared))
|
||||
.boxify()
|
||||
|
@ -745,7 +745,7 @@ impl BlobRepo {
|
||||
fetch_file_envelope(ctx, &self.blobstore.boxed(), node)
|
||||
.with_context({
|
||||
cloned!(path);
|
||||
move |_| format!("While fetching filenode for {} {}", path, node)
|
||||
move || format!("While fetching filenode for {} {}", path, node)
|
||||
})
|
||||
.from_err()
|
||||
.and_then({
|
||||
@ -2137,7 +2137,7 @@ impl CreateChangeset {
|
||||
event_id,
|
||||
)
|
||||
})
|
||||
.with_context(move |_| {
|
||||
.with_context(move || {
|
||||
format!(
|
||||
"While creating Changeset {:?}, uuid: {}",
|
||||
expected_nodeid, uuid
|
||||
|
@ -315,7 +315,7 @@ impl UploadEntries {
|
||||
Self::assert_in_blobstore(ctx.clone(), blobstore.clone(), node, is_tree);
|
||||
|
||||
assert
|
||||
.with_context(move |_| format!("While checking for path: {:?}", path))
|
||||
.with_context(move || format!("While checking for path: {:?}", path))
|
||||
.map_err(Error::from)
|
||||
}
|
||||
})
|
||||
@ -351,7 +351,7 @@ impl UploadEntries {
|
||||
);
|
||||
let node_key = node_key.clone();
|
||||
assert
|
||||
.with_context(move |_| {
|
||||
.with_context(move || {
|
||||
format!("While checking for a parent node: {}", node_key)
|
||||
})
|
||||
.from_err()
|
||||
|
@ -144,7 +144,7 @@ fn collect_fsnode_subentries(
|
||||
move |fsnode_id| {
|
||||
fsnode_id
|
||||
.load(ctx.clone(), &blobstore)
|
||||
.with_context(move |_| ErrorKind::MissingParent(fsnode_id))
|
||||
.context(ErrorKind::MissingParent(fsnode_id))
|
||||
}
|
||||
}))
|
||||
.collect()
|
||||
@ -194,7 +194,7 @@ fn collect_fsnode_subentries(
|
||||
.load(ctx.clone(), &blobstore)
|
||||
.with_context({
|
||||
cloned!(elem);
|
||||
move |_| {
|
||||
move || {
|
||||
ErrorKind::MissingSubentry(
|
||||
String::from_utf8_lossy(elem.as_ref()).to_string(),
|
||||
fsnode_id,
|
||||
|
@ -19,7 +19,7 @@ pub trait FutureFailureErrorExt: Future + Sized {
|
||||
fn with_context<D, F>(self, f: F) -> WithContextErrorFut<Self, F>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&Error) -> D;
|
||||
F: FnOnce() -> D;
|
||||
}
|
||||
|
||||
impl<F> FutureFailureErrorExt for F
|
||||
@ -36,7 +36,7 @@ where
|
||||
fn with_context<D, O>(self, f: O) -> WithContextErrorFut<Self, O>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
O: FnOnce(&Error) -> D,
|
||||
O: FnOnce() -> D,
|
||||
{
|
||||
WithContextErrorFut::new(self, f)
|
||||
}
|
||||
@ -51,7 +51,7 @@ impl<A, F, D> WithContextErrorFut<A, F>
|
||||
where
|
||||
A: Future<Error = Error>,
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&Error) -> D,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
pub fn new(future: A, displayable: F) -> Self {
|
||||
Self {
|
||||
@ -65,7 +65,7 @@ impl<A, F, D> Future for WithContextErrorFut<A, F>
|
||||
where
|
||||
A: Future<Error = Error>,
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&Error) -> D,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
type Item = A::Item;
|
||||
type Error = Context<D>;
|
||||
@ -78,7 +78,7 @@ where
|
||||
.take()
|
||||
.expect("poll called after future completion");
|
||||
|
||||
let context = f(&err);
|
||||
let context = f();
|
||||
Err(err.context(context))
|
||||
}
|
||||
Ok(item) => Ok(item),
|
||||
@ -133,7 +133,7 @@ pub trait FutureFailureExt: Future + Sized {
|
||||
fn with_context<D, F>(self, f: F) -> WithContextFut<Self, F>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&dyn Fail) -> D;
|
||||
F: FnOnce() -> D;
|
||||
}
|
||||
|
||||
impl<F> FutureFailureExt for F
|
||||
@ -151,7 +151,7 @@ where
|
||||
fn with_context<D, O>(self, f: O) -> WithContextFut<Self, O>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
O: FnOnce(&dyn Fail) -> D,
|
||||
O: FnOnce() -> D,
|
||||
{
|
||||
WithContextFut::new(self, f)
|
||||
}
|
||||
@ -207,7 +207,7 @@ where
|
||||
A: Future,
|
||||
A::Error: Fail,
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&dyn Fail) -> D,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
pub fn new(future: A, displayable: F) -> Self {
|
||||
Self {
|
||||
@ -222,7 +222,7 @@ where
|
||||
A: Future,
|
||||
A::Error: Fail,
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce(&dyn Fail) -> D,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
type Item = A::Item;
|
||||
type Error = Context<D>;
|
||||
@ -235,7 +235,7 @@ where
|
||||
.take()
|
||||
.expect("poll called after future completion");
|
||||
|
||||
let context = f(&err);
|
||||
let context = f();
|
||||
Err(err.context(context))
|
||||
}
|
||||
Ok(item) => Ok(item),
|
||||
@ -261,7 +261,7 @@ mod test {
|
||||
#[should_panic]
|
||||
fn poll_after_completion_fail_with_context() {
|
||||
let err = err::<(), _>(format_err!("foo").context("bar"));
|
||||
let mut err = err.with_context(move |_| "baz");
|
||||
let mut err = err.with_context(|| "baz");
|
||||
let _ = err.poll();
|
||||
let _ = err.poll();
|
||||
}
|
||||
@ -279,7 +279,7 @@ mod test {
|
||||
#[should_panic]
|
||||
fn poll_after_completion_error_with_context() {
|
||||
let err = err::<(), _>(format_err!("foo"));
|
||||
let mut err = err.with_context(move |_| "baz");
|
||||
let mut err = err.with_context(|| "baz");
|
||||
let _ = err.poll();
|
||||
let _ = err.poll();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ pub trait StreamFailureExt: Stream + Sized {
|
||||
fn with_context<D, F>(self, f: F) -> WithContextStream<Self, F>
|
||||
where
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&dyn Fail) -> D;
|
||||
F: FnMut() -> D;
|
||||
}
|
||||
|
||||
impl<S> StreamFailureExt for S
|
||||
@ -37,7 +37,7 @@ where
|
||||
fn with_context<D, F>(self, f: F) -> WithContextStream<Self, F>
|
||||
where
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&dyn Fail) -> D,
|
||||
F: FnMut() -> D,
|
||||
{
|
||||
WithContextStream::new(self, f)
|
||||
}
|
||||
@ -93,7 +93,7 @@ where
|
||||
A: Stream,
|
||||
A::Error: Fail,
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&dyn Fail) -> D,
|
||||
F: FnMut() -> D,
|
||||
{
|
||||
type Item = A::Item;
|
||||
type Error = Context<D>;
|
||||
@ -101,7 +101,7 @@ where
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
match self.inner.poll() {
|
||||
Err(err) => {
|
||||
let context = (&mut self.displayable)(&err);
|
||||
let context = (&mut self.displayable)();
|
||||
Err(err.context(context))
|
||||
}
|
||||
Ok(item) => Ok(item),
|
||||
@ -118,7 +118,7 @@ pub trait StreamFailureErrorExt: Stream + Sized {
|
||||
fn with_context<D, F>(self, f: F) -> WithContextErrorStream<Self, F>
|
||||
where
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&Error) -> D;
|
||||
F: FnMut() -> D;
|
||||
}
|
||||
|
||||
impl<S> StreamFailureErrorExt for S
|
||||
@ -135,7 +135,7 @@ where
|
||||
fn with_context<D, F>(self, f: F) -> WithContextErrorStream<Self, F>
|
||||
where
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&Error) -> D,
|
||||
F: FnMut() -> D,
|
||||
{
|
||||
WithContextErrorStream::new(self, f)
|
||||
}
|
||||
@ -189,7 +189,7 @@ impl<A, F, D> Stream for WithContextErrorStream<A, F>
|
||||
where
|
||||
A: Stream<Error = Error>,
|
||||
D: Display + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&Error) -> D,
|
||||
F: FnMut() -> D,
|
||||
{
|
||||
type Item = A::Item;
|
||||
type Error = Context<D>;
|
||||
@ -197,7 +197,7 @@ where
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
match self.inner.poll() {
|
||||
Err(err) => {
|
||||
let context = (&mut self.displayable)(&err);
|
||||
let context = (&mut self.displayable)();
|
||||
Err(err.context(context))
|
||||
}
|
||||
Ok(item) => Ok(item),
|
||||
@ -230,7 +230,7 @@ mod test {
|
||||
Err(format_err!("foo").context("bar")),
|
||||
Err(format_err!("baz").context("wiggle")),
|
||||
]);
|
||||
let mut stream = stream.with_context(move |_| "foo");
|
||||
let mut stream = stream.with_context(|| "foo");
|
||||
let _ = stream.poll();
|
||||
let _ = stream.poll();
|
||||
let _ = stream.poll();
|
||||
@ -256,7 +256,7 @@ mod test {
|
||||
Err(format_err!("bar")),
|
||||
Err(format_err!("baz")),
|
||||
]);
|
||||
let mut stream = stream.with_context(move |_| "foo");
|
||||
let mut stream = stream.with_context(|| "foo");
|
||||
let _ = stream.poll();
|
||||
let _ = stream.poll();
|
||||
let _ = stream.poll();
|
||||
|
@ -598,7 +598,7 @@ where
|
||||
(
|
||||
bundle2items,
|
||||
recv.from_err()
|
||||
.with_context(|_| format!("While extracting bundle2 remainder"))
|
||||
.context("While extracting bundle2 remainder")
|
||||
.from_err()
|
||||
.boxify(),
|
||||
)
|
||||
|
@ -191,7 +191,7 @@ where
|
||||
(
|
||||
responses.boxify(),
|
||||
recv.from_err()
|
||||
.with_context(|_| format!("While handling batch command"))
|
||||
.context("While handling batch command")
|
||||
.from_err()
|
||||
.and_then(|input| input)
|
||||
.boxify(),
|
||||
|
@ -425,7 +425,7 @@ impl HookManager {
|
||||
cloned!(hook_name);
|
||||
move |he| (hook_name, he)
|
||||
})
|
||||
.with_context(move |_| format!("while executing hook {}", hook_name))
|
||||
.with_context(move || format!("while executing hook {}", hook_name))
|
||||
.from_err()
|
||||
.boxify()
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ impl HgBlobChangeset {
|
||||
Ok(Some(cs))
|
||||
}
|
||||
})
|
||||
.with_context(move |_| {
|
||||
.with_context(move || {
|
||||
format!(
|
||||
"Error while deserializing changeset retrieved from key '{}'",
|
||||
key
|
||||
|
@ -216,7 +216,7 @@ pub fn fetch_file_envelope_opt(
|
||||
}
|
||||
Ok(Some(envelope))
|
||||
})
|
||||
.with_context(|_| ErrorKind::FileNodeDeserializeFailed(blobstore_key))
|
||||
.context(ErrorKind::FileNodeDeserializeFailed(blobstore_key))
|
||||
.from_err()
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ pub fn fetch_manifest_envelope_opt(
|
||||
}
|
||||
Ok(Some(envelope))
|
||||
})
|
||||
.with_context(|_| ErrorKind::ManifestDeserializeFailed(blobstore_key))
|
||||
.context(ErrorKind::ManifestDeserializeFailed(blobstore_key))
|
||||
.from_err()
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ fn fetch_bonsai_changesets(
|
||||
cloned!(ctx, repo);
|
||||
move |bcs_id| repo.get_bonsai_changeset(ctx, bcs_id).from_err()
|
||||
})
|
||||
.with_context(move |_| format!("While intitial bonsai changesets fetching"))
|
||||
.context("While intitial bonsai changesets fetching")
|
||||
.map_err(Error::from)
|
||||
.from_err()
|
||||
}))
|
||||
|
@ -142,7 +142,7 @@ where
|
||||
})
|
||||
}
|
||||
})
|
||||
.with_context(move |_| {
|
||||
.with_context(move || {
|
||||
format!(
|
||||
"While decoding delta cache for file id {}, path {}",
|
||||
node, path
|
||||
|
@ -123,7 +123,7 @@ impl NewBlobs {
|
||||
Ok(Self {
|
||||
root_manifest,
|
||||
sub_entries: stream::futures_unordered(entries)
|
||||
.with_context(move |_| {
|
||||
.with_context(move || {
|
||||
format!(
|
||||
"While walking dependencies of Root Manifest with id {:?}",
|
||||
manifest_root_id
|
||||
@ -309,7 +309,7 @@ pub fn upload_changeset(
|
||||
// DO NOT replace and_then() with join() or futures_ordered()!
|
||||
// It may result in a combinatoral explosion in mergy repos (see D14100259)
|
||||
p1.and_then(|p1| p2.map(|p2| (p1, p2)))
|
||||
.with_context(move |_| format!("While fetching parents for Changeset {}", node))
|
||||
.with_context(move || format!("While fetching parents for Changeset {}", node))
|
||||
.from_err()
|
||||
.and_then(move |(p1, p2)| {
|
||||
let cs_metadata = ChangesetMetadata {
|
||||
|
Loading…
Reference in New Issue
Block a user