2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 #ifndef SHAREDDATALAYER_ERROR_HPP_
18 #define SHAREDDATALAYER_ERROR_HPP_
20 #include <system_error>
22 /* Error codes defined here are for SDL internal usage only.
23 * Error codes meant to be used by SDL clients are defined in sdl/errorqueries.hpp.
25 * Error code handling in SDL goes following way:
27 * - Implementation sets so called implementation specific error codes (e.g AsyncRedisCommandDispatcherErrorCode
28 * and AsyncRedisConnection::ErrorCode).
29 * - All implementation specific error codes have mapping to InternalErrors. This mapping is handled by overriding
30 * std::error_category default_error_condition function in all implementation specific error code categories.
31 * - All InternalErrors are mapped to shareddatalayer::Errors which SDL client can conveniently use in
32 * its error handling implemention. This mapping is handled by overriding std::error_category equivalent function in
33 * SharedDataLayerErrorCategory.
34 * - Async API error codes have corresponding exceptions in sync API. When modifying other one (async API error codes or
35 * sync API exceptions) check the need for similar modification to other one also.
37 * When adding a new implementation specific error code, do also needed updates to mappings described above.
38 * At least mapping from new implementation specific error code error code to InternalError is always needed.
41 namespace shareddatalayer
43 enum class InternalError
47 SDL_NOT_CONNECTED_TO_BACKEND,
48 SDL_ERROR_CODE_LOGIC_ERROR,
49 SDL_RECEIVED_INVALID_PARAMETER,
50 BACKEND_CONNECTION_LOST,
52 BACKEND_REJECTED_REQUEST,
56 std::error_condition make_error_condition(shareddatalayer::InternalError ec);
60 enum class AsyncRedisCommandDispatcherErrorCode
71 //Keep this always as last item. Used in unit tests to loop all enum values.
75 std::error_code make_error_code(AsyncRedisCommandDispatcherErrorCode errorCode);
76 AsyncRedisCommandDispatcherErrorCode& operator++ (AsyncRedisCommandDispatcherErrorCode& ecEnum);
83 struct is_error_condition_enum<shareddatalayer::InternalError> : public true_type { };
86 struct is_error_code_enum<shareddatalayer::redis::AsyncRedisCommandDispatcherErrorCode>: public true_type { };