Future::onError replaced with Future::thenError

Summary:
Replace Future::onError with Future::thenError:
 * to remove ambiguous typing
 * to ensure that the executor is not lost and the returned Future is still bound to an executor

See:
https://fb.workplace.com/groups/fbcode/permalink/2002251863144976/
for details.

Reviewed By: yfeldblum

Differential Revision: D13784772

fbshipit-source-id: 1d3ede848b7d31c7a197a21b4ff2b31e840040a5
This commit is contained in:
Lee Howes 2019-01-30 09:45:02 -08:00 committed by Facebook Github Bot
parent ff1357e076
commit 967e3f8a1c
10 changed files with 56 additions and 50 deletions

View File

@ -130,20 +130,21 @@ folly::Future<fuse_entry_out> EdenDispatcher::lookup(
}
});
})
.onError([](const std::system_error& err) {
// Translate ENOENT into a successful response with an
// inode number of 0 and a large entry_valid time, to let the kernel
// cache this negative lookup result.
if (isEnoent(err)) {
fuse_entry_out entry = {};
entry.attr_valid =
std::numeric_limits<decltype(entry.attr_valid)>::max();
entry.entry_valid =
std::numeric_limits<decltype(entry.entry_valid)>::max();
return entry;
}
throw err;
});
.thenError(
folly::tag_t<std::system_error>{}, [](const std::system_error& err) {
// Translate ENOENT into a successful response with an
// inode number of 0 and a large entry_valid time, to let the kernel
// cache this negative lookup result.
if (isEnoent(err)) {
fuse_entry_out entry = {};
entry.attr_valid =
std::numeric_limits<decltype(entry.attr_valid)>::max();
entry.entry_valid =
std::numeric_limits<decltype(entry.entry_valid)>::max();
return entry;
}
throw err;
});
}
folly::Future<Dispatcher::Attr> EdenDispatcher::setattr(

View File

@ -291,21 +291,24 @@ folly::Future<folly::Unit> EdenMount::setupDotEden(TreeInodePtr root) {
dotEdenInodeNumber_ = dotEdenInode->getNodeId();
});
})
.onError([=](const InodeError& /*err*/) {
auto dotEdenInode =
getRootInode()->mkdir(PathComponentPiece{kDotEdenName}, 0744);
dotEdenInode->symlink("root"_pc, config_->getMountPath().stringPiece());
dotEdenInode->symlink(
"socket"_pc, serverState_->getSocketPath().stringPiece());
dotEdenInode->symlink(
"client"_pc, config_->getClientDirectory().stringPiece());
.thenError(
folly::tag_t<facebook::eden::InodeError>{},
[=](const InodeError& /*err*/) {
auto dotEdenInode =
getRootInode()->mkdir(PathComponentPiece{kDotEdenName}, 0744);
dotEdenInode->symlink(
"root"_pc, config_->getMountPath().stringPiece());
dotEdenInode->symlink(
"socket"_pc, serverState_->getSocketPath().stringPiece());
dotEdenInode->symlink(
"client"_pc, config_->getClientDirectory().stringPiece());
createDotEdenSymlink(dotEdenInode);
createDotEdenSymlink(dotEdenInode);
// We must assign this after we've built out the contents, otherwise
// we'll lock ourselves out of populating more entries
dotEdenInodeNumber_ = dotEdenInode->getNodeId();
});
// We must assign this after we've built out the contents, otherwise
// we'll lock ourselves out of populating more entries
dotEdenInodeNumber_ = dotEdenInode->getNodeId();
});
}
EdenMount::~EdenMount() {}
@ -821,7 +824,7 @@ folly::Future<folly::Unit> EdenMount::startFuse() {
.thenValue([this](FuseChannel::StopFuture&& fuseCompleteFuture) {
fuseInitSuccessful(std::move(fuseCompleteFuture));
})
.onError([this](folly::exception_wrapper&& ew) {
.thenError([this](folly::exception_wrapper&& ew) {
unconditionallySetState(State::FUSE_ERROR);
return makeFuture<folly::Unit>(std::move(ew));
});
@ -883,7 +886,7 @@ void EdenMount::fuseInitSuccessful(
SerializedInodeMap{} // placeholder
));
})
.onError([this](folly::exception_wrapper&& ew) {
.thenError([this](folly::exception_wrapper&& ew) {
XLOG(ERR) << "session complete with err: " << ew.what();
fuseCompletionPromise_.setException(std::move(ew));
});

View File

@ -303,7 +303,7 @@ void InodeMap::setupParentLookupPromise(
mode](const InodePtr& inode) {
startChildLookup(inode, name, isUnlinked, childInodeNumber, hash, mode);
})
.onError([this, childInodeNumber](const folly::exception_wrapper& ex) {
.thenError([this, childInodeNumber](const folly::exception_wrapper& ex) {
// Fail all pending lookups on the child
inodeLoadFailed(childInodeNumber, ex);
});

View File

@ -1943,7 +1943,7 @@ Future<Unit> TreeInode::loadGitIgnoreThenDiff(
if (dtype_t::Symlink == gitignoreInode->getType()) {
return getMount()
->resolveSymlink(gitignoreInode)
.onError([](const folly::exception_wrapper& ex) {
.thenError([](const folly::exception_wrapper& ex) {
XLOG(WARN) << "error resolving gitignore symlink: "
<< folly::exceptionStr(ex);
return InodePtr{};
@ -1971,7 +1971,7 @@ Future<Unit> TreeInode::loadGitIgnoreThenDiff(
}
return fileInode->readAll(CacheHint::LikelyNeededAgain)
.onError([](const folly::exception_wrapper& ex) {
.thenError([](const folly::exception_wrapper& ex) {
XLOG(WARN) << "error reading ignore file: " << folly::exceptionStr(ex);
return std::string{};
})

View File

@ -52,7 +52,7 @@ TEST(FuseTest, initMount) {
testMount.getEdenMount()
->startFuse()
.thenValue([](auto&&) { XLOG(INFO) << "startFuse() succeeded"; })
.onError([&](const folly::exception_wrapper& ew) {
.thenError([&](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "startFuse() failed: " << folly::exceptionStr(ew);
});

View File

@ -845,14 +845,16 @@ folly::Future<Hash> HgBackingStore::importManifest(Hash commitId) {
if (unionStore_) {
auto hash = importTreeManifest(commitId);
if (FLAGS_allow_flatmanifest_fallback) {
return std::move(hash).onError([this, commitId](const MissingKeyError&) {
// We don't have a tree manifest available for the target rev,
// so let's fall through to the full flat manifest importer.
XLOG(INFO) << "no treemanifest data available for revision "
<< commitId.toString()
<< ": falling back to slower flatmanifest import";
return importFlatManifest(commitId);
});
return std::move(hash).thenError(
folly::tag_t<MissingKeyError>{},
[this, commitId](const MissingKeyError&) {
// We don't have a tree manifest available for the target rev,
// so let's fall through to the full flat manifest importer.
XLOG(INFO) << "no treemanifest data available for revision "
<< commitId.toString()
<< ": falling back to slower flatmanifest import";
return importFlatManifest(commitId);
});
}
return hash;
}

View File

@ -61,7 +61,7 @@ TakeoverData takeoverMounts(
.thenValue([&expectedMessage](UnixSocket::Message&& msg) {
expectedMessage = std::move(msg);
})
.onError([&expectedMessage](folly::exception_wrapper&& ew) {
.thenError([&expectedMessage](folly::exception_wrapper&& ew) {
expectedMessage = folly::makeUnexpected(std::move(ew));
})
.ensure([&evb] { evb.terminateLoopSoon(); });

View File

@ -238,7 +238,7 @@ void TakeoverServer::connectionAccepted(
XLOG(INFO) << "takeover socket connection received";
auto* handlerRawPtr = handler.get();
handlerRawPtr->start()
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
XLOG(ERR) << "error processing takeover connection request: "
<< folly::exceptionStr(ew);
})

View File

@ -96,7 +96,7 @@ TEST_F(FakeBackingStoreTest, getBlob) {
folly::exception_wrapper future4Error;
std::move(future4)
.thenValue([](auto&&) { FAIL() << "future4 should not succeed\n"; })
.onError([&](const folly::exception_wrapper& ew) {
.thenError([&](const folly::exception_wrapper& ew) {
future4Failed = true;
future4Error = ew;
});

View File

@ -130,7 +130,7 @@ void testSendDataAndFiles(DataSize dataSize, size_t numFiles) {
}
socket1->send(UnixSocket::Message(sendBuf->cloneAsValue(), std::move(files)))
.thenValue([](auto&&) { XLOG(DBG3) << "send complete"; })
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "send error: " << ew.what();
});
@ -139,7 +139,7 @@ void testSendDataAndFiles(DataSize dataSize, size_t numFiles) {
.thenValue([&receivedMessage](UnixSocket::Message&& msg) {
receivedMessage = std::move(msg);
})
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "receive error: " << ew.what();
})
.ensure([&]() { evb.terminateLoopSoon(); });
@ -212,7 +212,7 @@ TEST(FutureUnixSocket, receiveQueue) {
.thenValue([n, &receivedMessages](UnixSocket::Message&& msg) {
receivedMessages.emplace_back(n, std::move(msg));
})
.onError([n, &evb](const folly::exception_wrapper& ew) {
.thenError([n, &evb](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "receive " << n << " error: " << ew.what();
evb.terminateLoopSoon();
});
@ -227,7 +227,7 @@ TEST(FutureUnixSocket, receiveQueue) {
auto sendBuf = IOBuf(IOBuf::WRAP_BUFFER, ByteRange{StringPiece{msg}});
socket1->send(std::move(sendBuf))
.thenValue([](auto&&) { XLOG(DBG3) << "send complete"; })
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "send error: " << ew.what();
});
}
@ -261,7 +261,7 @@ TEST(FutureUnixSocket, attachEventBase) {
const std::string msgData(100, 'a');
s1.send(UnixSocket::Message(IOBuf(IOBuf::COPY_BUFFER, msgData)))
.thenValue([](auto&&) { XLOG(DBG3) << "send complete"; })
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "send error: " << ew.what();
});
std::optional<UnixSocket::Message> receivedMessage;
@ -269,7 +269,7 @@ TEST(FutureUnixSocket, attachEventBase) {
.thenValue([&receivedMessage](UnixSocket::Message&& msg) {
receivedMessage = std::move(msg);
})
.onError([](const folly::exception_wrapper& ew) {
.thenError([](const folly::exception_wrapper& ew) {
ADD_FAILURE() << "receive error: " << ew.what();
})
.ensure([&]() { evb->terminateLoopSoon(); });