sapling/eden/fs/store/hg/HgImportPyError.h
Adam Simpkins 8352b88299 include the exception type name in hg_import_helper.py errors
Summary:
Update hg_import_helper.py to include the exception type name in error
responses.  Add a new HgImportPyError class in the C++ code to include both the
python exception type name and the message string.

In the future this will give us the ability to perform special handling based
on the python exception type, rather than just on the message contents.

Reviewed By: bolinfest

Differential Revision: D6333613

fbshipit-source-id: 1074bbf9fa25ee8b1abeadc38b1a4f569bc18d13
2017-11-15 13:31:58 -08:00

69 lines
1.5 KiB
C++

/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include <folly/Range.h>
#include <stdexcept>
#include <string>
namespace facebook {
namespace eden {
/**
* All exceptions received from the python hg_import_helper.py script
* are thrown in C++ as HgImportPyError exceptions.
*/
class HgImportPyError : public std::exception {
public:
HgImportPyError(folly::StringPiece errorType, folly::StringPiece message);
const char* what() const noexcept override {
return fullMessage_.c_str();
}
/**
* The name of the python exception type.
*/
folly::StringPiece errorType() const noexcept {
return errorType_;
}
/**
* The python exception message.
*/
folly::StringPiece message() const noexcept {
return message_;
}
private:
static constexpr folly::StringPiece kSeparator{": "};
/**
* The full message to return from what().
* This always has the form "errorType: message"
*/
const std::string fullMessage_;
/**
* The name of the python exception type.
* This points to a substring of fullMessage_.
*/
const folly::StringPiece errorType_;
/**
* The python exception message.
* This points to a substring of fullMessage_.
*/
const folly::StringPiece message_;
};
} // namespace eden
} // namespace facebook