/* * 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. * */ #pragma once #include #include #include #include #include "eden/fs/service/gen-cpp2/eden_types.h" namespace facebook { namespace eden { /* * Helper functions for constructing thrift EdenError objects. */ /** * Construct an EdenError from an error code and message. * * The message is used literally in this case, and is not passed through * folly::format() if no format arguments are supplied.. */ EdenError newEdenError(int errorCode, folly::StringPiece message); /** * Construct an EdenError from an error code, plus a format * string and format arguments. */ template EdenError newEdenError(int errorCode, folly::StringPiece fmt, Args&&... args) { auto e = EdenError(folly::sformat(fmt, std::forward(args)...)); e.set_errorCode(errorCode); return e; } /** * Construct an EdenError from a format string and format arguments, with no * error code. */ template EdenError newEdenError(folly::StringPiece fmt, Args&&... args) { return EdenError(folly::sformat(fmt, std::forward(args)...)); } /** * Construct an EdenError from a std::system_error. * * This automatically extracts the error code. */ EdenError newEdenError(const std::system_error& ex); /** * Construct an EdenError from an exception. * * If the exception is an instance of std::system_error the error code will be * extracted. */ EdenError newEdenError(const std::exception& ex); /** * Construct an EdenError from a folly::exception_wrapper. */ EdenError newEdenError(const folly::exception_wrapper& ew); } // namespace eden } // namespace facebook