Skip to content

Commit 241adee

Browse files
Chandhana Solainathanmeta-codesync[bot]
authored andcommitted
Add ErrorArg wrapper for Exception and In-place errors
Summary: Introduce `ErrorArg`, a wrapper class that can be implicitly constructed from either a `const std::exception&` or a `std::string`. This allows factory methods to accept both exception and string arguments with a single signature, avoiding templates or overloads. This will be useful when user uses the same function for either logging exception if it is available or just the error message if exception is not available (in-place error handling). Reviewed By: vilatto Differential Revision: D96323869 fbshipit-source-id: aefd8e25c84fdc90c642efef3e5e970c92d557ca
1 parent 97a8a1d commit 241adee

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

eden/fs/telemetry/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ cpp_library(
123123
headers = [
124124
"EdenComponent.h",
125125
"EdenErrorInfo.h",
126+
"ErrorArg.h",
126127
],
127128
)
128129

eden/fs/telemetry/ErrorArg.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This software may be used and distributed according to the terms of the
5+
* GNU General Public License version 2.
6+
*/
7+
8+
#pragma once
9+
10+
#include <cstdint>
11+
#include <optional>
12+
#include <string>
13+
14+
namespace facebook::eden {
15+
16+
/**
17+
* Wrapper that can be implicitly constructed from either a std::exception or a
18+
* std::string. Extracts error message, and optionally error code and error
19+
* name (from std::system_error).
20+
*/
21+
class ErrorArg {
22+
public:
23+
// Implicit conversions — callers can pass either type directly.
24+
ErrorArg(const std::exception& ex);
25+
ErrorArg(std::string message);
26+
ErrorArg(const char* message);
27+
28+
std::string message;
29+
// Numeric errno from std::system_error (e.g. ENOENT=2, EACCES=13).
30+
std::optional<int64_t> errorCode;
31+
std::optional<std::string> errorName;
32+
std::optional<std::string> exceptionType;
33+
};
34+
35+
} // namespace facebook::eden

0 commit comments

Comments
 (0)