2828namespace iceberg {
2929
3030// / \brief Error types for iceberg.
31- // / TODO: add more and sort them based on some rules.
3231enum class ErrorKind {
33- kNoSuchNamespace ,
3432 kAlreadyExists ,
35- kNoSuchTable ,
3633 kCommitStateUnknown ,
37- kInvalidSchema ,
3834 kInvalidArgument ,
39- kIOError ,
40- kNotImplemented ,
41- kUnknownError ,
42- kNotSupported ,
4335 kInvalidExpression ,
36+ kInvalidSchema ,
37+ kIOError ,
4438 kJsonParseError ,
39+ kNoSuchNamespace ,
40+ kNoSuchTable ,
4541 kNotFound ,
42+ kNotImplemented ,
43+ kNotSupported ,
44+ kUnknownError ,
4645};
4746
4847// / \brief Error with a kind and a message.
@@ -63,19 +62,27 @@ using Result = expected<T, E>;
6362
6463using Status = Result<void >;
6564
66- // / \brief Create an unexpected error with kNotImplemented
65+ // / \brief Create an unexpected error with kAlreadyExists
6766template <typename ... Args>
68- auto NotImplementedError (const std::format_string<Args...> fmt, Args&&... args)
67+ auto AlreadyExistsError (const std::format_string<Args...> fmt, Args&&... args)
6968 -> unexpected<Error> {
70- return unexpected<Error>({.kind = ErrorKind::kNotImplemented ,
69+ return unexpected<Error>({.kind = ErrorKind::kAlreadyExists ,
7170 .message = std::format (fmt, std::forward<Args>(args)...)});
7271}
7372
74- // / \brief Create an unexpected error with kJsonParseError
73+ // / \brief Create an unexpected error with kCommitStateUnknown
7574template <typename ... Args>
76- auto JsonParseError (const std::format_string<Args...> fmt, Args&&... args)
75+ auto CommitStateUnknownError (const std::format_string<Args...> fmt, Args&&... args)
7776 -> unexpected<Error> {
78- return unexpected<Error>({.kind = ErrorKind::kJsonParseError ,
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 ,
7986 .message = std::format (fmt, std::forward<Args>(args)...)});
8087}
8188
@@ -87,4 +94,67 @@ auto InvalidExpressionError(const std::format_string<Args...> fmt, Args&&... arg
8794 .message = std::format (fmt, std::forward<Args>(args)...)});
8895}
8996
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+ }
159+
90160} // namespace iceberg
0 commit comments