sapling/eden/fs/service/EdenError.h
Adam Simpkins 251da81f36 update all copyright statements to "2016-present"
Summary:
Update copyright statements to "2016-present".  This makes our updated lint
rules happy and complies with the recommended license header statement.

Reviewed By: wez, bolinfest

Differential Revision: D4433594

fbshipit-source-id: e9ecb1c1fc66e4ec49c1f046c6a98d425b13bc27
2017-01-20 22:03:02 -08:00

74 lines
1.9 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.
*
*/
#pragma once
#include <folly/ExceptionWrapper.h>
#include <folly/Format.h>
#include <folly/Range.h>
#include <system_error>
#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 <class... Args>
EdenError newEdenError(int errorCode, folly::StringPiece fmt, Args&&... args) {
auto e = EdenError(folly::sformat(fmt, std::forward<Args>(args)...));
e.set_errorCode(errorCode);
return e;
}
/**
* Construct an EdenError from a format string and format arguments, with no
* error code.
*/
template <class... Args>
EdenError newEdenError(folly::StringPiece fmt, Args&&... args) {
return EdenError(folly::sformat(fmt, std::forward<Args>(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);
}
}