unilink  0.4.3
A simple C++ library for unified async communication
error_codes.hpp
Go to the documentation of this file.
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 unilink {
22 
26 enum class ErrorCode {
27  Success = 0,
28  Unknown,
31  IoError,
32 
33  // Connection related
37  TimedOut,
40 
41  // Server related
42  PortInUse,
44 
45  // Lifecycle
46  Stopped,
48 };
49 
53 inline std::string to_string(ErrorCode code) {
54  switch (code) {
55  case ErrorCode::Success:
56  return "Success";
57  case ErrorCode::Unknown:
58  return "Unknown Error";
60  return "Invalid Configuration";
62  return "Internal Error";
63  case ErrorCode::IoError:
64  return "I/O Error";
66  return "Connection Refused";
68  return "Connection Reset";
70  return "Connection Aborted";
72  return "Operation Timed Out";
74  return "Not Connected";
76  return "Already Connected";
78  return "Port Already In Use";
80  return "Access Denied";
81  case ErrorCode::Stopped:
82  return "Stopped";
84  return "Failed to Start";
85  default:
86  return "Unknown Error Code";
87  }
88 }
89 
90 } // namespace unilink