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 <format>
27#include <string>
28#include <type_traits>
29
32
33namespace iceberg {
34
36enum class ErrorKind {
37 kAlreadyExists,
38 kAuthenticationFailed,
39 kBadRequest,
40 kCommitFailed,
41 kCommitStateUnknown,
42 kCompressError,
43 kDecompressError,
44 kForbidden,
45 kInternalServerError,
46 kInvalid, // For general invalid errors
47 kInvalidArgument,
48 kInvalidArrowData,
49 kInvalidExpression,
50 kInvalidManifest,
51 kInvalidManifestList,
52 kInvalidSchema,
53 kIOError,
54 kJsonParseError,
55 kNamespaceNotEmpty,
56 kNoSuchNamespace,
57 kNoSuchPlanId,
58 kNoSuchPlanTask,
59 kNoSuchTable,
60 kNoSuchWarehouse,
61 kNoSuchView,
62 kNotAllowed,
63 kNotAuthorized,
64 kNotFound,
65 kNotImplemented,
66 kNotSupported,
67 kRestError,
68 kRetryableValidationFailed,
69 kServiceUnavailable,
70 kTokenExpired,
71 kUnknownError,
72 kValidationFailed,
73};
74
76struct ICEBERG_EXPORT [[nodiscard]] Error {
77 ErrorKind kind;
78 std::string message;
79};
80
82template <typename T>
84 using type = Error;
85};
86
88template <typename T, typename E = typename DefaultError<T>::type>
90
91using Status = Result<void>;
92
94#define DEFINE_ERROR_FUNCTION(name) \
95 template <typename... Args> \
96 inline auto name(const std::format_string<Args...> fmt, Args&&... args) \
97 -> ::iceberg::unexpected<Error> { \
98 return ::iceberg::unexpected<Error>( \
99 {ErrorKind::k##name, std::format(fmt, std::forward<Args>(args)...)}); \
100 } \
101 inline auto name(std::string message) -> ::iceberg::unexpected<Error> { \
102 return ::iceberg::unexpected<Error>({ErrorKind::k##name, std::move(message)}); \
103 }
104
105DEFINE_ERROR_FUNCTION(AlreadyExists)
106DEFINE_ERROR_FUNCTION(AuthenticationFailed)
107DEFINE_ERROR_FUNCTION(BadRequest)
108DEFINE_ERROR_FUNCTION(CommitFailed)
109DEFINE_ERROR_FUNCTION(CommitStateUnknown)
110DEFINE_ERROR_FUNCTION(CompressError)
111DEFINE_ERROR_FUNCTION(DecompressError)
112DEFINE_ERROR_FUNCTION(Forbidden)
113DEFINE_ERROR_FUNCTION(InternalServerError)
115DEFINE_ERROR_FUNCTION(InvalidArgument)
116DEFINE_ERROR_FUNCTION(InvalidArrowData)
117DEFINE_ERROR_FUNCTION(InvalidExpression)
118DEFINE_ERROR_FUNCTION(InvalidManifest)
119DEFINE_ERROR_FUNCTION(InvalidManifestList)
120DEFINE_ERROR_FUNCTION(InvalidSchema)
122DEFINE_ERROR_FUNCTION(JsonParseError)
123DEFINE_ERROR_FUNCTION(NamespaceNotEmpty)
124DEFINE_ERROR_FUNCTION(NoSuchNamespace)
125DEFINE_ERROR_FUNCTION(NoSuchPlanId)
126DEFINE_ERROR_FUNCTION(NoSuchPlanTask)
127DEFINE_ERROR_FUNCTION(NoSuchTable)
128DEFINE_ERROR_FUNCTION(NoSuchWarehouse)
129DEFINE_ERROR_FUNCTION(NoSuchView)
130DEFINE_ERROR_FUNCTION(NotAllowed)
131DEFINE_ERROR_FUNCTION(NotAuthorized)
132DEFINE_ERROR_FUNCTION(NotFound)
133DEFINE_ERROR_FUNCTION(NotImplemented)
134DEFINE_ERROR_FUNCTION(NotSupported)
135DEFINE_ERROR_FUNCTION(RestError)
136DEFINE_ERROR_FUNCTION(RetryableValidationFailed)
137DEFINE_ERROR_FUNCTION(ServiceUnavailable)
138DEFINE_ERROR_FUNCTION(TokenExpired)
139DEFINE_ERROR_FUNCTION(UnknownError)
140DEFINE_ERROR_FUNCTION(ValidationFailed)
141
142#undef DEFINE_ERROR_FUNCTION
143
144template <typename T>
145concept AsResult = std::derived_from<std::remove_cvref_t<T>,
146 Result<typename std::remove_cvref_t<T>::value_type>>;
147
148template <AsResult T>
149using ResultValueT = typename std::remove_cvref_t<T>::value_type;
150
151} // namespace iceberg
Definition expected.h:1199
Definition result.h:145
A C++20 backport of C++23 std::expected, used as the storage type behind iceberg::Result.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
ErrorKind
Error types for iceberg.
Definition result.h:36
#define DEFINE_ERROR_FUNCTION(name)
Macro to define error creation functions.
Definition result.h:94
/brief Default error trait
Definition result.h:83
Error with a kind and a message.
Definition result.h:76