Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 Jinwoo Sung
3 : : *
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
7 : : *
8 : : * http://www.apache.org/licenses/LICENSE-2.0
9 : : *
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.
15 : : */
16 : :
17 : : #pragma once
18 : :
19 : : #include <string>
20 : :
21 : : namespace wirestead {
22 : :
23 : : /**
24 : : * @brief Structured error codes for Wirestead
25 : : */
26 : : enum class ErrorCode {
27 : : Success = 0,
28 : : Unknown,
29 : : InvalidConfiguration,
30 : : InternalError,
31 : : IoError,
32 : :
33 : : // Connection related
34 : : ConnectionRefused,
35 : : ConnectionReset,
36 : : ConnectionAborted,
37 : : TimedOut,
38 : : NotConnected,
39 : : AlreadyConnected,
40 : :
41 : : // Server related
42 : : PortInUse,
43 : : AccessDenied,
44 : :
45 : : // Lifecycle
46 : : Stopped,
47 : : StartFailed
48 : : };
49 : :
50 : : /**
51 : : * @brief Convert ErrorCode to human-readable string
52 : : */
53 : 16 : inline std::string to_string(ErrorCode code) {
54 [ + + + + : 16 : switch (code) {
+ + + + +
+ + + + +
+ + ]
55 : 1 : case ErrorCode::Success:
56 : 2 : return "Success";
57 : 1 : case ErrorCode::Unknown:
58 : 2 : return "Unknown Error";
59 : 1 : case ErrorCode::InvalidConfiguration:
60 : 2 : return "Invalid Configuration";
61 : 1 : case ErrorCode::InternalError:
62 : 2 : return "Internal Error";
63 : 1 : case ErrorCode::IoError:
64 : 2 : return "I/O Error";
65 : 1 : case ErrorCode::ConnectionRefused:
66 : 2 : return "Connection Refused";
67 : 1 : case ErrorCode::ConnectionReset:
68 : 2 : return "Connection Reset";
69 : 1 : case ErrorCode::ConnectionAborted:
70 : 2 : return "Connection Aborted";
71 : 1 : case ErrorCode::TimedOut:
72 : 2 : return "Operation Timed Out";
73 : 1 : case ErrorCode::NotConnected:
74 : 2 : return "Not Connected";
75 : 1 : case ErrorCode::AlreadyConnected:
76 : 2 : return "Already Connected";
77 : 1 : case ErrorCode::PortInUse:
78 : 2 : return "Port Already In Use";
79 : 1 : case ErrorCode::AccessDenied:
80 : 2 : return "Access Denied";
81 : 1 : case ErrorCode::Stopped:
82 : 2 : return "Stopped";
83 : 1 : case ErrorCode::StartFailed:
84 : 2 : return "Failed to Start";
85 : 1 : default:
86 : 2 : return "Unknown Error Code";
87 : : }
88 : : }
89 : :
90 : : } // namespace wirestead
|