2016-12-21 04:19:15 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-12-21 04:19:15 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2016-12-21 04:19:15 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2018-01-06 00:36:29 +03:00
|
|
|
#include "eden/fs/utils/Bug.h"
|
2016-12-21 04:19:15 +03:00
|
|
|
|
|
|
|
#include <folly/Conv.h>
|
|
|
|
#include <folly/ExceptionWrapper.h>
|
2018-05-01 07:20:51 +03:00
|
|
|
#include <folly/logging/xlog.h>
|
2016-12-21 04:19:15 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
static std::atomic<int> edenBugDisabledCount{0};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
EdenBug::EdenBug(const char* file, int lineNumber)
|
|
|
|
: file_(file), lineNumber_(lineNumber), message_("!!BUG!! ") {}
|
|
|
|
|
|
|
|
EdenBug::EdenBug(EdenBug&& other) noexcept
|
|
|
|
: file_(other.file_),
|
|
|
|
lineNumber_(other.lineNumber_),
|
|
|
|
message_(std::move(other.message_)) {
|
2019-11-23 00:26:28 +03:00
|
|
|
other.processed_ = true;
|
2016-12-21 04:19:15 +03:00
|
|
|
}
|
|
|
|
|
2019-11-23 00:26:28 +03:00
|
|
|
EdenBug::~EdenBug() {
|
|
|
|
XCHECK(processed_);
|
2016-12-21 04:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
folly::exception_wrapper EdenBug::toException() {
|
|
|
|
logError();
|
2019-11-23 00:26:28 +03:00
|
|
|
processed_ = true;
|
2016-12-21 04:19:15 +03:00
|
|
|
return folly::exception_wrapper(std::runtime_error(message_));
|
|
|
|
}
|
|
|
|
|
2018-05-02 02:23:09 +03:00
|
|
|
void EdenBug::throwException() {
|
|
|
|
toException().throw_exception();
|
|
|
|
}
|
|
|
|
|
2016-12-21 04:19:15 +03:00
|
|
|
void EdenBug::logError() {
|
2018-03-17 02:53:56 +03:00
|
|
|
XLOG(CRITICAL) << "EDEN_BUG at " << file_ << ":" << lineNumber_ << ": "
|
|
|
|
<< message_;
|
2016-12-21 04:19:15 +03:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Crash in debug builds.
|
|
|
|
// However, allow test code to disable crashing so that we can exercise
|
|
|
|
// EDEN_BUG() code paths in tests.
|
|
|
|
if (edenBugDisabledCount.load() == 0) {
|
2018-01-06 00:36:29 +03:00
|
|
|
XLOG(FATAL) << "crashing due to EDEN_BUG";
|
2016-12-21 04:19:15 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
EdenBugDisabler::EdenBugDisabler() {
|
|
|
|
++edenBugDisabledCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
EdenBugDisabler::~EdenBugDisabler() {
|
|
|
|
--edenBugDisabledCount;
|
|
|
|
}
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|