mirror of
https://github.com/facebook/sapling.git
synced 2025-01-08 06:37:26 +03:00
f6685834de
Summary: Update Eden's thrift service handler code to accept BinaryHash arguments either as 20-byte binary values or as 40-byte hexadecimal values. This will make it easier to transition APIs like getScmStatusBetweenRevisions() to use 20-byte binary hash arguments without breaking existing clients. Reviewed By: wez Differential Revision: D7341607 fbshipit-source-id: 3e952211900d3ec4b9c2073cf3afd55ae7e253ea
48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2016-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.
|
|
*
|
|
*/
|
|
#include "eden/fs/service/EdenError.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
EdenError newEdenError(int errorCode, folly::StringPiece message) {
|
|
auto e = EdenError(message.str());
|
|
e.set_errorCode(errorCode);
|
|
return e;
|
|
}
|
|
|
|
EdenError newEdenError(const std::system_error& ex) {
|
|
return newEdenError(ex.code().value(), ex.what());
|
|
}
|
|
|
|
EdenError newEdenError(const std::exception& ex) {
|
|
const auto* edenError = dynamic_cast<const EdenError*>(&ex);
|
|
if (edenError) {
|
|
return *edenError;
|
|
}
|
|
const auto* systemError = dynamic_cast<const std::system_error*>(&ex);
|
|
if (systemError) {
|
|
return newEdenError(*systemError);
|
|
}
|
|
return EdenError(folly::exceptionStr(ex).toStdString());
|
|
}
|
|
|
|
EdenError newEdenError(const folly::exception_wrapper& ew) {
|
|
EdenError err;
|
|
if (!ew.with_exception([&err](const EdenError& ex) { err = ex; }) &&
|
|
!ew.with_exception(
|
|
[&err](const std::system_error& ex) { err = newEdenError(ex); })) {
|
|
err = EdenError(folly::exceptionStr(ew).toStdString());
|
|
}
|
|
return err;
|
|
}
|
|
} // namespace eden
|
|
} // namespace facebook
|