1515#pragma once
1616
1717#include < cstring>
18+ #include < format>
1819#include < iosfwd>
1920#include < memory>
2021#include < string>
2122#include < utility>
2223
2324#include " util/compare.h"
2425#include " util/macros.h"
25- #include " util/string_builder .h"
26+ #include " util/to_string_ostreamable .h"
2627#include " util/visibility.h"
2728
2829#ifdef ICEBERG_EXTRA_ERROR_CONTEXT
@@ -86,16 +87,10 @@ namespace iceberg {
8687enum class StatusCode : char {
8788 OK = 0 ,
8889 OutOfMemory = 1 ,
89- KeyError = 2 ,
90- TypeError = 3 ,
91- Invalid = 4 ,
92- IOError = 5 ,
93- CapacityError = 6 ,
94- IndexError = 7 ,
95- Cancelled = 8 ,
96- NotImplemented = 9 ,
97- SerializationError = 10 ,
98- AlreadyExists = 11 ,
90+ TypeError = 2 ,
91+ Invalid = 3 ,
92+ IOError = 4 ,
93+ NotImplemented = 5 ,
9994 UnknownError = 127
10095};
10196
@@ -160,14 +155,14 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
160155 static Status OK () { return Status (); }
161156
162157 template <typename ... Args>
163- static Status FromArgs (StatusCode code, Args&&... args) {
164- return Status (code, util::StringBuilder ( std::forward<Args> (args) ...));
158+ static Status FromArgs (StatusCode code, std::string_view fmt, Args&&... args) {
159+ return Status (code, std::vformat (fmt, std::make_format_args (args...) ));
165160 }
166161
167162 template <typename ... Args>
168163 static Status FromDetailAndArgs (StatusCode code, std::shared_ptr<StatusDetail> detail,
169- Args&&... args) {
170- return Status (code, util::StringBuilder ( std::forward<Args> (args) ...),
164+ std::string_view fmt, Args&&... args) {
165+ return Status (code, std::vformat (fmt, std::make_format_args (args...) ),
171166 std::move (detail));
172167 }
173168
@@ -177,12 +172,6 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
177172 return Status::FromArgs (StatusCode::OutOfMemory, std::forward<Args>(args)...);
178173 }
179174
180- // / Return an error status for failed key lookups (e.g. column name in a table)
181- template <typename ... Args>
182- static Status KeyError (Args&&... args) {
183- return Status::FromArgs (StatusCode::KeyError, std::forward<Args>(args)...);
184- }
185-
186175 // / Return an error status for type errors (such as mismatching data types)
187176 template <typename ... Args>
188177 static Status TypeError (Args&&... args) {
@@ -201,43 +190,13 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
201190 return Status::FromArgs (StatusCode::IOError, std::forward<Args>(args)...);
202191 }
203192
204- // / Return an error status when a container's capacity would exceed its limits
205- template <typename ... Args>
206- static Status CapacityError (Args&&... args) {
207- return Status::FromArgs (StatusCode::CapacityError, std::forward<Args>(args)...);
208- }
209-
210- // / Return an error status when an index is out of bounds
211- template <typename ... Args>
212- static Status IndexError (Args&&... args) {
213- return Status::FromArgs (StatusCode::IndexError, std::forward<Args>(args)...);
214- }
215-
216- // / Return an error status for cancelled operation
217- template <typename ... Args>
218- static Status Cancelled (Args&&... args) {
219- return Status::FromArgs (StatusCode::Cancelled, std::forward<Args>(args)...);
220- }
221-
222193 // / Return an error status when an operation or a combination of operation and
223194 // / data types is unimplemented
224195 template <typename ... Args>
225196 static Status NotImplemented (Args&&... args) {
226197 return Status::FromArgs (StatusCode::NotImplemented, std::forward<Args>(args)...);
227198 }
228199
229- // / Return an error status when some (de)serialization operation failed
230- template <typename ... Args>
231- static Status SerializationError (Args&&... args) {
232- return Status::FromArgs (StatusCode::SerializationError, std::forward<Args>(args)...);
233- }
234-
235- // / Return an error status for already exists errors
236- template <typename ... Args>
237- static Status AlreadyExists (Args&&... args) {
238- return Status::FromArgs (StatusCode::AlreadyExists, std::forward<Args>(args)...);
239- }
240-
241200 // / Return an error status for unknown errors
242201 template <typename ... Args>
243202 static Status UnknownError (Args&&... args) {
@@ -249,27 +208,14 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
249208
250209 // / Return true iff the status indicates an out-of-memory error.
251210 constexpr bool IsOutOfMemory () const { return code () == StatusCode::OutOfMemory; }
252- // / Return true iff the status indicates a key lookup error.
253- constexpr bool IsKeyError () const { return code () == StatusCode::KeyError; }
254211 // / Return true iff the status indicates a type error.
255212 constexpr bool IsTypeError () const { return code () == StatusCode::TypeError; }
256213 // / Return true iff the status indicates invalid data.
257214 constexpr bool IsInvalid () const { return code () == StatusCode::Invalid; }
258215 // / Return true iff the status indicates an IO-related failure.
259216 constexpr bool IsIOError () const { return code () == StatusCode::IOError; }
260- // / Return true iff the status indicates a container reaching capacity limits.
261- constexpr bool IsCapacityError () const { return code () == StatusCode::CapacityError; }
262- // / Return true iff the status indicates an out of bounds index.
263- constexpr bool IsIndexError () const { return code () == StatusCode::IndexError; }
264- // / Return true iff the status indicates a cancelled operation.
265- constexpr bool IsCancelled () const { return code () == StatusCode::Cancelled; }
266217 // / Return true iff the status indicates an unimplemented operation.
267218 constexpr bool IsNotImplemented () const { return code () == StatusCode::NotImplemented; }
268- // / Return true iff the status indicates a (de)serialization failure
269- constexpr bool IsSerializationError () const {
270- return code () == StatusCode::SerializationError;
271- }
272- constexpr bool IsAlreadyExists () const { return code () == StatusCode::AlreadyExists; }
273219 // / Return true iff the status indicates an unknown error.
274220 constexpr bool IsUnknownError () const { return code () == StatusCode::UnknownError; }
275221
@@ -278,12 +224,6 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
278224 // / The string "OK" is returned for success.
279225 std::string ToString () const ;
280226
281- // / \brief Return a string representation of this status without
282- // / context lines suitable for printing.
283- // /
284- // / The string "OK" is returned for success.
285- std::string ToStringWithoutContextLines () const ;
286-
287227 // / \brief Return a string representation of the status code, without the message
288228 // / text or POSIX code information.
289229 std::string CodeAsString () const ;
@@ -320,9 +260,6 @@ class ICEBERG_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Stat
320260 void Warn () const ;
321261 void Warn (const std::string& message) const ;
322262
323- [[noreturn]] void Abort () const ;
324- [[noreturn]] void Abort (const std::string& message) const ;
325-
326263#ifdef ICEBERG_EXTRA_ERROR_CONTEXT
327264 void AddContextLine (const char * filename, int line, const char * expr);
328265#endif
0 commit comments