iceberg-cpp
Loading...
Searching...
No Matches
result.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <concepts>
26#include <expected>
27#include <format>
28#include <string>
29#include <type_traits>
30
32
33namespace iceberg {
34
36enum class ErrorKind {
37 kAlreadyExists,
38 kAuthenticationFailed,
39 kBadRequest,
40 kCommitFailed,
41 kCommitStateUnknown,
42 kDecompressError,
43 kForbidden,
44 kInternalServerError,
45 kInvalid, // For general invalid errors
46 kInvalidArgument,
47 kInvalidArrowData,
48 kInvalidExpression,
49 kInvalidManifest,
50 kInvalidManifestList,
51 kInvalidSchema,
52 kIOError,
53 kJsonParseError,
54 kNamespaceNotEmpty,
55 kNoSuchNamespace,
56 kNoSuchPlanId,
57 kNoSuchPlanTask,
58 kNoSuchTable,
59 kNoSuchWarehouse,
60 kNoSuchView,
61 kNotAllowed,
62 kNotAuthorized,
63 kNotFound,
64 kNotImplemented,
65 kNotSupported,
66 kRestError,
67 kRetryableValidationFailed,
68 kServiceUnavailable,
69 kTokenExpired,
70 kUnknownError,
71 kValidationFailed,
72};
73
75struct ICEBERG_EXPORT [[nodiscard]] Error {
76 ErrorKind kind;
77 std::string message;
78};
79
81template <typename T>
83 using type = Error;
84};
85
87template <typename T, typename E = typename DefaultError<T>::type>
88using Result = std::expected<T, E>;
89
90using Status = Result<void>;
91
93#define DEFINE_ERROR_FUNCTION(name) \
94 template <typename... Args> \
95 inline auto name(const std::format_string<Args...> fmt, Args&&... args) \
96 -> std::unexpected<Error> { \
97 return std::unexpected<Error>( \
98 {ErrorKind::k##name, std::format(fmt, std::forward<Args>(args)...)}); \
99 } \
100 inline auto name(std::string message) -> std::unexpected<Error> { \
101 return std::unexpected<Error>({ErrorKind::k##name, std::move(message)}); \
102 }
103
104DEFINE_ERROR_FUNCTION(AlreadyExists)
105DEFINE_ERROR_FUNCTION(AuthenticationFailed)
106DEFINE_ERROR_FUNCTION(BadRequest)
107DEFINE_ERROR_FUNCTION(CommitFailed)
108DEFINE_ERROR_FUNCTION(CommitStateUnknown)
109DEFINE_ERROR_FUNCTION(DecompressError)
110DEFINE_ERROR_FUNCTION(Forbidden)
111DEFINE_ERROR_FUNCTION(InternalServerError)
113DEFINE_ERROR_FUNCTION(InvalidArgument)
114DEFINE_ERROR_FUNCTION(InvalidArrowData)
115DEFINE_ERROR_FUNCTION(InvalidExpression)
116DEFINE_ERROR_FUNCTION(InvalidManifest)
117DEFINE_ERROR_FUNCTION(InvalidManifestList)
118DEFINE_ERROR_FUNCTION(InvalidSchema)
120DEFINE_ERROR_FUNCTION(JsonParseError)
121DEFINE_ERROR_FUNCTION(NamespaceNotEmpty)
122DEFINE_ERROR_FUNCTION(NoSuchNamespace)
123DEFINE_ERROR_FUNCTION(NoSuchPlanId)
124DEFINE_ERROR_FUNCTION(NoSuchPlanTask)
125DEFINE_ERROR_FUNCTION(NoSuchTable)
126DEFINE_ERROR_FUNCTION(NoSuchWarehouse)
127DEFINE_ERROR_FUNCTION(NoSuchView)
128DEFINE_ERROR_FUNCTION(NotAllowed)
129DEFINE_ERROR_FUNCTION(NotAuthorized)
130DEFINE_ERROR_FUNCTION(NotFound)
131DEFINE_ERROR_FUNCTION(NotImplemented)
132DEFINE_ERROR_FUNCTION(NotSupported)
133DEFINE_ERROR_FUNCTION(RestError)
134DEFINE_ERROR_FUNCTION(RetryableValidationFailed)
135DEFINE_ERROR_FUNCTION(ServiceUnavailable)
136DEFINE_ERROR_FUNCTION(TokenExpired)
137DEFINE_ERROR_FUNCTION(UnknownError)
138DEFINE_ERROR_FUNCTION(ValidationFailed)
139
140#undef DEFINE_ERROR_FUNCTION
141
142template <typename T>
143concept AsResult = std::derived_from<std::remove_cvref_t<T>,
144 Result<typename std::remove_cvref_t<T>::value_type>>;
145
146template <AsResult T>
147using ResultValueT = typename std::remove_cvref_t<T>::value_type;
148
149} // namespace iceberg
Definition result.h:143
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
ErrorKind
Error types for iceberg.
Definition result.h:36
std::expected< T, E > Result
Result alias.
Definition result.h:88
#define DEFINE_ERROR_FUNCTION(name)
Macro to define error creation functions.
Definition result.h:93
/brief Default error trait
Definition result.h:82
Error with a kind and a message.
Definition result.h:75