improve error messages if the hg import helper fails to start

Summary:
Throw a slightly nicer error message if the hg import helper exits before
returning a `CMD_STARTED` response or an error response.

When switching from the `hg_import_helper.py` script to the
`hg debugedenimporthelper` subcommand we are slightly more likely to encounter
errors during startup.  For instance, if the repository path was not a valid
repository the `hg_import_helper.py` code would send an error message back
that the `HgImporter.cpp` code could parse.  However, we unfortunately can't
catch errors loading the repository the same way when using an `hg`
subcommand.  If it fails to load the repository it will simply print an error
message to stderr and then bail out before it invokes the
`debugedenimporthelper` code.

Reviewed By: chadaustin

Differential Revision: D14222266

fbshipit-source-id: cd60e5a61725d45a816b74f63b9969b29ade2160
This commit is contained in:
Adam Simpkins 2019-02-27 13:40:32 -08:00 committed by Facebook Github Bot
parent 4568ff90b7
commit 01490a26da

View File

@ -234,6 +234,11 @@ std::string findInPath(folly::StringPiece executable) {
namespace facebook {
namespace eden {
class HgImporterEofError : public HgImporterError {
public:
using HgImporterError::HgImporterError;
};
HgImporter::HgImporter(
AbsolutePathPiece repoPath,
LocalStore* store,
@ -332,7 +337,21 @@ HgImporter::HgImporter(
ImporterOptions HgImporter::waitForHelperStart() {
// Wait for the import helper to send the CMD_STARTED message indicating
// that it has started successfully.
auto header = readChunkHeader(0, "CMD_STARTED");
ChunkHeader header;
try {
header = readChunkHeader(0, "CMD_STARTED");
} catch (const HgImporterEofError& error) {
// If we get EOF trying to read the initial response this generally
// indicates that the import helper exited with an error early on during
// startup, before it could send us a success or error message.
//
// It should have normally printed an error message to stderr in this case,
// which is normally redirected to our edenfs.log file.
throw HgImporterError(
"error starting Mercurial import helper. "
"Check edenfs.log for the error messages from the import helper.");
}
if (header.command != CMD_STARTED) {
// This normally shouldn't happen. If an error occurs, the
// hg_import_helper script should send an error chunk causing
@ -844,7 +863,7 @@ void HgImporter::readFromHelper(void* buf, size_t size, StringPiece context) {
if (bytesRead != size) {
// The helper process closed the pipe early.
// This generally means that it exited.
HgImporterError err(
HgImporterEofError err(
"received unexpected EOF from hg_import_helper.py after ",
bytesRead,
" bytes while reading ",