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