sapling/eden/fs/utils/SystemError.h
Adam Simpkins a3c582d708 check for std::generic_category when looking for errno errors
Summary:
Add a new utils/SystemError.h header with helper functions to check if a
`std::system_error` contains an errno value.

Most of the code in Eden previously only checked for `std::system_category`
when looking for errno values.  `std::generic_category` is the correct category
to use for errno exceptions, but folly/Exception.h incorrectly throws them as
`std::system_category` today.  This change makes Eden treat either error type
as errno values for now.

Reviewed By: yfeldblum

Differential Revision: D7329999

fbshipit-source-id: 67a3c3ea10371c53a2e34236b7575deac4cbd53a
2018-03-20 13:38:45 -07:00

38 lines
1.1 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 <system_error>
namespace facebook {
namespace eden {
/**
* Return true if this exception contains an errno value in ex.code().value()
*/
inline bool isErrnoError(const std::system_error& ex) {
// std::generic_category is the correct category to represent errno values.
// However folly/Exception.h unfortunately throws errno values as
// std::system_category for now.
return (
ex.code().category() == std::generic_category() ||
ex.code().category() == std::system_category());
}
/**
* Return true if this exception is equivalent to an ENOENT error code.
*/
inline bool isEnoent(const std::system_error& ex) {
return isErrnoError(ex) && ex.code().value() == ENOENT;
}
} // namespace eden
} // namespace facebook