@@ -61,99 +61,28 @@ using Result = expected<T, E>;
6161
6262using Status = Result<void >;
6363
64- // / \brief Create an unexpected error with kAlreadyExists
65- template <typename ... Args>
66- auto AlreadyExistsError (const std::format_string<Args...> fmt, Args&&... args)
67- -> unexpected<Error> {
68- return unexpected<Error>({.kind = ErrorKind::kAlreadyExists ,
69- .message = std::format (fmt, std::forward<Args>(args)...)});
70- }
71-
72- // / \brief Create an unexpected error with kCommitStateUnknown
73- template <typename ... Args>
74- auto CommitStateUnknownError (const std::format_string<Args...> fmt, Args&&... args)
75- -> unexpected<Error> {
76- return unexpected<Error>({.kind = ErrorKind::kCommitStateUnknown ,
77- .message = std::format (fmt, std::forward<Args>(args)...)});
78- }
79-
80- // / \brief Create an unexpected error with kInvalidArgument
81- template <typename ... Args>
82- auto InvalidArgumentError (const std::format_string<Args...> fmt, Args&&... args)
83- -> unexpected<Error> {
84- return unexpected<Error>({.kind = ErrorKind::kInvalidArgument ,
85- .message = std::format (fmt, std::forward<Args>(args)...)});
86- }
87-
88- // / \brief Create an unexpected error with kInvalidExpression
89- template <typename ... Args>
90- auto InvalidExpressionError (const std::format_string<Args...> fmt, Args&&... args)
91- -> unexpected<Error> {
92- return unexpected<Error>({.kind = ErrorKind::kInvalidExpression ,
93- .message = std::format (fmt, std::forward<Args>(args)...)});
94- }
95-
96- // / \brief Create an unexpected error with kInvalidSchema
97- template <typename ... Args>
98- auto InvalidSchemaError (const std::format_string<Args...> fmt, Args&&... args)
99- -> unexpected<Error> {
100- return unexpected<Error>({.kind = ErrorKind::kInvalidSchema ,
101- .message = std::format (fmt, std::forward<Args>(args)...)});
102- }
103-
104- // / \brief Create an unexpected error with kIOError
105- template <typename ... Args>
106- auto IOError (const std::format_string<Args...> fmt, Args&&... args) -> unexpected<Error> {
107- return unexpected<Error>({.kind = ErrorKind::kIOError ,
108- .message = std::format (fmt, std::forward<Args>(args)...)});
109- }
110-
111- // / \brief Create an unexpected error with kJsonParseError
112- template <typename ... Args>
113- auto JsonParseError (const std::format_string<Args...> fmt, Args&&... args)
114- -> unexpected<Error> {
115- return unexpected<Error>({.kind = ErrorKind::kJsonParseError ,
116- .message = std::format (fmt, std::forward<Args>(args)...)});
117- }
118-
119- // / \brief Create an unexpected error with kNoSuchNamespace
120- template <typename ... Args>
121- auto NoSuchNamespaceError (const std::format_string<Args...> fmt, Args&&... args)
122- -> unexpected<Error> {
123- return unexpected<Error>({.kind = ErrorKind::kNoSuchNamespace ,
124- .message = std::format (fmt, std::forward<Args>(args)...)});
125- }
126-
127- // / \brief Create an unexpected error with kNoSuchTable
128- template <typename ... Args>
129- auto NoSuchTableError (const std::format_string<Args...> fmt, Args&&... args)
130- -> unexpected<Error> {
131- return unexpected<Error>({.kind = ErrorKind::kNoSuchTable ,
132- .message = std::format (fmt, std::forward<Args>(args)...)});
133- }
134-
135- // / \brief Create an unexpected error with kNotImplemented
136- template <typename ... Args>
137- auto NotImplementedError (const std::format_string<Args...> fmt, Args&&... args)
138- -> unexpected<Error> {
139- return unexpected<Error>({.kind = ErrorKind::kNotImplemented ,
140- .message = std::format (fmt, std::forward<Args>(args)...)});
141- }
142-
143- // / \brief Create an unexpected error with kNotSupported
144- template <typename ... Args>
145- auto NotSupportedError (const std::format_string<Args...> fmt, Args&&... args)
146- -> unexpected<Error> {
147- return unexpected<Error>({.kind = ErrorKind::kNotSupported ,
148- .message = std::format (fmt, std::forward<Args>(args)...)});
149- }
150-
151- // / \brief Create an unexpected error with kUnknownError
152- template <typename ... Args>
153- auto UnknownError (const std::format_string<Args...> fmt, Args&&... args)
154- -> unexpected<Error> {
155- return unexpected<Error>({.kind = ErrorKind::kUnknownError ,
156- .message = std::format (fmt, std::forward<Args>(args)...)});
157- }
64+ // / \brief Macro to define error creation functions
65+ #define DEFINE_ERROR_FUNCTION (name ) \
66+ template <typename ... Args> \
67+ auto name (const std::format_string<Args...> fmt, Args&&... args) \
68+ -> unexpected<Error> { \
69+ return unexpected<Error>( \
70+ {ErrorKind::k##name, std::format (fmt, std::forward<Args>(args)...)}); \
71+ }
72+
73+ DEFINE_ERROR_FUNCTION (AlreadyExists)
74+ DEFINE_ERROR_FUNCTION (CommitStateUnknown)
75+ DEFINE_ERROR_FUNCTION (InvalidArgument)
76+ DEFINE_ERROR_FUNCTION (InvalidExpression)
77+ DEFINE_ERROR_FUNCTION (InvalidSchema)
78+ DEFINE_ERROR_FUNCTION (IOError)
79+ DEFINE_ERROR_FUNCTION (JsonParseError)
80+ DEFINE_ERROR_FUNCTION (NoSuchNamespace)
81+ DEFINE_ERROR_FUNCTION (NoSuchTable)
82+ DEFINE_ERROR_FUNCTION (NotImplemented)
83+ DEFINE_ERROR_FUNCTION (NotSupported)
84+ DEFINE_ERROR_FUNCTION (UnknownError)
85+
86+ #undef DEFINE_ERROR_FUNCTION
15887
15988} // namespace iceberg
0 commit comments