mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
fix some exceptions thrown by FsOverlay
Summary: Update `FsOverlay::validateHeader()` to throw `EdenError` exceptions rather than `std::system_error`. These exceptions are generated when we find invalid data, rather than from system calls that return errno values. Previously the code was using `folly::throwSystemErrorExplicit()` and `folly:throwSystemError()`, and passing in a made-up `EIO` value. However, the latter two calls were incorrectly using `folly::throwSystemError()` rather than `throwSystemErrorExplicit()`. As a result the `EIO` parameter was being treated as part of the error message, and the code was appending the error description for whatever value `errno` happened to be set to at the moment. This fixes the code to just throw `EdenError` exception types, since these errors aren't caused by a real `errno` value. Reviewed By: strager Differential Revision: D16577698 fbshipit-source-id: 9487c34f04da99d397611f005f00f02114b12094
This commit is contained in:
parent
4b15926035
commit
e93e9b3531
@ -7,6 +7,9 @@
|
||||
#include "eden/fs/inodes/overlay/FsOverlay.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include <folly/Exception.h>
|
||||
#include <folly/File.h>
|
||||
#include <folly/FileUtil.h>
|
||||
@ -15,8 +18,8 @@
|
||||
#include <folly/io/IOBuf.h>
|
||||
#include <folly/logging/xlog.h>
|
||||
#include <thrift/lib/cpp2/protocol/Serializer.h>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include "eden/fs/service/EdenError.h"
|
||||
#include "eden/fs/utils/PathFuncs.h"
|
||||
|
||||
namespace facebook {
|
||||
@ -208,7 +211,7 @@ InodeNumber FsOverlay::scanForNextInodeNumber() {
|
||||
auto dir = optional<overlay::OverlayDir>{};
|
||||
try {
|
||||
dir = loadOverlayDir(dirInodeNumber);
|
||||
} catch (std::system_error& error) {
|
||||
} catch (const std::exception& error) {
|
||||
XLOG_IF(WARN, !encounteredBrokenDirectory)
|
||||
<< "Ignoring failure to load directory inode " << dirInodeNumber
|
||||
<< ": " << error.what();
|
||||
@ -608,8 +611,7 @@ void FsOverlay::validateHeader(
|
||||
folly::StringPiece headerId) {
|
||||
if (contents.size() < kHeaderLength) {
|
||||
// Something wrong with the file (may be corrupted)
|
||||
folly::throwSystemErrorExplicit(
|
||||
EIO,
|
||||
throw newEdenError(
|
||||
"Overlay file (inode ",
|
||||
inodeNumber,
|
||||
") is too short for header: size=",
|
||||
@ -625,8 +627,7 @@ void FsOverlay::validateHeader(
|
||||
auto id = cursor.readFixedString(kHeaderIdentifierDir.size());
|
||||
StringPiece identifier{id};
|
||||
if (identifier.compare(headerId) != 0) {
|
||||
folly::throwSystemError(
|
||||
EIO,
|
||||
throw newEdenError(
|
||||
"unexpected overlay header identifier : ",
|
||||
folly::hexlify(ByteRange{identifier}));
|
||||
}
|
||||
@ -634,7 +635,7 @@ void FsOverlay::validateHeader(
|
||||
// Validate header version
|
||||
auto version = cursor.readBE<uint32_t>();
|
||||
if (version != kHeaderVersion) {
|
||||
folly::throwSystemError(EIO, "Unexpected overlay version :", version);
|
||||
throw newEdenError("Unexpected overlay version :", version);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user