Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
Invalid.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** Invalid.cpp
6*/
7
14
15namespace CustomExceptions
16{
17
18 InvalidIp::InvalidIp(const std::string &error)
19 {
20 _msg = "Error: The ip you provided '";
21 _msg += error;
22 _msg += "' is incorrect, it should be of type ipV4.\n";
23 _msg += "Hint: An IpV4 is:\n";
24 _msg += "-\tComposed of 4 whole numbers\n";
25 _msg += "-\tEach whole number ranges from 0 to 255\n";
26 _msg += "-\tEach whole number is connected to the next one by a '.'\n";
27 _msg += "-\tHere is a typical example of an IpV4 address: '127.0.0.1";
28 _buffer = _msg.c_str();
29 };
30
32
33 const char *InvalidIp::what() const noexcept
34 {
35 return _buffer;
36 }
37
38 InvalidPort::InvalidPort(const std::string &error)
39 {
40 _msg = "Error: The port you provided '";
41 _msg += error;
42 _msg += "' is incorrect.\n";
43 _msg += "Hint: The port should be a whole number in the range between 0 and 65535";
44 _buffer = _msg.c_str();
45 };
46
48
49 const char *InvalidPort::what() const noexcept
50 {
51 return _buffer;
52 }
53
54 InvalidType::InvalidType(const std::string &extraDetails)
55 {
56 _msg = "Error: The content present in std::any does not match ";
57 _msg += "the provided type (or is just missing).";
58 if (!extraDetails.empty()) {
59 _msg += "\n(" + extraDetails + ")";
60 }
61 _buffer = _msg.c_str();
62 };
63
65
66 const char *InvalidType::what() const noexcept
67 {
68 return _buffer;
69 }
70
71 InvalidUsername::InvalidUsername(const std::string &error)
72 {
73 _msg = "Error: The username you provided '";
74 _msg += error;
75 _msg += "' is incorrect.\n";
76 _msg += "Hint1/3: The Username should not be empty or contain special characters like emojis.\n";
77 _msg += "Hint2/3: The Username should not exceed '" + Recoded::myToString(USERNAME_MAX_LENGTH) + "' characters and only be made of printable ascii characters as well as the ' ' character.\n";
78 _msg += "Hint3/3: The Username should not be below '" + Recoded::myToString(USERNAME_MIN_LENGTH) + "' characters or be composed of only whitespaces.";
79 _buffer = _msg.c_str();
80 };
81
83
84 const char *InvalidUsername::what() const noexcept
85 {
86 return _buffer;
87 }
88
89 InvalidOperation::InvalidOperation(const std::string &error)
90 {
91 _msg = "Error: The operation you tried to perform did not succeed.\n";
92 if (!error.empty()) {
93 _msg += "The operation provided the following message: '" + error + "'.\n";
94 }
95 _buffer = _msg.c_str();
96 };
97
99
100 const char *InvalidOperation::what() const noexcept
101 {
102 return _buffer;
103 }
104
105 InvalidChoice::InvalidChoice(const std::string &error)
106 {
107 _msg = "Error: The option you chose is invalid.\n";
108 if (!error.empty()) {
109 _msg += "The function in charge of processing your choice provided the following message: '" + error + "'.\n";
110 }
111 _buffer = _msg.c_str();
112 };
113
115
116 const char *InvalidChoice::what() const noexcept
117 {
118 return _buffer;
119 }
120
121 InvalidDuration::InvalidDuration(const std::string &duration, const std::string &min, const std::string &max)
122 {
123 _msg = "Error: The duration you provided is invalid.\n";
124 if (!min.empty() && !max.empty()) {
125 _msg += "The duration must be in the range '" + min + "' to '" + max + "'.\n";
126 } else if (!min.empty() && max.empty()) {
127 _msg += "The duration must be greater than or equal to '" + min + "'.\n";
128 } else if (min.empty() && !max.empty()) {
129 _msg += "The duration must be less than or equal to '" + max + "'.\n";
130 } else {
131 _msg += "The duration must be a valid number.\n";
132 }
133 _msg += "The duration was: '";
134 _msg += duration;
135 _msg += "'.";
136 _buffer = _msg.c_str();
137 };
138
140
141 const char *InvalidDuration::what() const noexcept
142 {
143 return _buffer;
144 }
145
146 InvalidNumber::InvalidNumber(const std::string &number, const std::string &min, const std::string &max)
147 {
148 _msg = "Error: The number you provided is invalid.\n";
149 if (!min.empty() && !max.empty()) {
150 _msg += "The number must be in the range '" + min + "' to '" + max + "'.\n";
151 } else if (!min.empty() && max.empty()) {
152 _msg += "The number must be greater than or equal to '" + min + "'.\n";
153 } else if (min.empty() && !max.empty()) {
154 _msg += "The number must be less than or equal to '" + max + "'.\n";
155 } else {
156 _msg += "The number must be a valid number.\n";
157 }
158 _msg += "The number was: '";
159 _msg += number;
160 _msg += "'.";
161 _buffer = _msg.c_str();
162 };
163
165
166 const char *InvalidNumber::what() const noexcept
167 {
168 return _buffer;
169 }
170
171 InvalidTOML::InvalidTOML(const std::string &path, const std::string &error)
172 {
173 _msg = "Error: The TOML file you provided is invalid\n";
174 _msg += "The filepath you provided is '" + path + "'.\n";
175 _msg += "The detailed error is '" + error + "'.";
176 _buffer = _msg.c_str();
177 };
178
180
181 const char *InvalidTOML::what() const noexcept
182 {
183 return _buffer;
184 }
185
186 InvalidTOMLKeyType::InvalidTOMLKeyType(const std::string &tomlPath, const std::string &tomlKey, const std::string &currentType, const std::string &expectedType)
187 {
188 _msg = "Error: The type of the key '";
189 _msg += tomlKey;
190 _msg += "' is '";
191 _msg += currentType;
192 _msg += "' but '";
193 _msg += expectedType;
194 _msg += "' type was expected for the configuration file '";
195 _msg += tomlPath;
196 _msg += "'.";
197 _buffer = _msg.c_str();
198 };
199
201
202 const char *InvalidTOMLKeyType::what() const noexcept
203 {
204 return _buffer;
205 }
206
207}
This file contains the definitions of custom exception classes used to inform the user about various ...
~InvalidChoice()
Destroy the InvalidChoice object.
Definition Invalid.cpp:114
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:116
InvalidChoice(const std::string &error="")
Construct a new InvalidChoice object.
Definition Invalid.cpp:105
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:141
~InvalidDuration()
Destroy the InvalidDuration object.
Definition Invalid.cpp:139
InvalidDuration(const std::string &duration="", const std::string &min="", const std::string &max="")
Construct a new InvalidDuration object.
Definition Invalid.cpp:121
~InvalidIp()
Destroy the InvalidIp object.
Definition Invalid.cpp:31
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:33
InvalidIp(const std::string &error="")
Construct a new InvalidIp object.
Definition Invalid.cpp:18
~InvalidNumber()
Destroy the InvalidNumber object.
Definition Invalid.cpp:164
InvalidNumber(const std::string &number="", const std::string &min="", const std::string &max="")
Construct a new InvalidNumber object.
Definition Invalid.cpp:146
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:166
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:100
~InvalidOperation()
Destroy the InvalidOperation object.
Definition Invalid.cpp:98
InvalidOperation(const std::string &error="")
Construct a new InvalidOperation object.
Definition Invalid.cpp:89
~InvalidPort()
Destroy the InvalidPort object.
Definition Invalid.cpp:47
InvalidPort(const std::string &error="")
Construct a new InvalidPort object.
Definition Invalid.cpp:38
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:49
InvalidTOMLKeyType(const std::string &tomlPath="", const std::string &tomlKey="", const std::string &currentType="", const std::string &expectedType="")
Construct a new InvalidTOMLKeyType object.
Definition Invalid.cpp:186
~InvalidTOMLKeyType()
Destroy the InvalidTOMLKeyType object.
Definition Invalid.cpp:200
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:202
InvalidTOML(const std::string &path="", const std::string &error="")
Construct a new InvalidTOML object.
Definition Invalid.cpp:171
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:181
~InvalidTOML()
Destroy the InvalidTOML object.
Definition Invalid.cpp:179
InvalidType(const std::string &extraDetails="")
Construct a new InvalidType object.
Definition Invalid.cpp:54
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:66
~InvalidType()
Destroy the InvalidType object.
Definition Invalid.cpp:64
InvalidUsername(const std::string &error="")
Construct a new InvalidUsername object.
Definition Invalid.cpp:71
const char * what() const noexcept
Retrieves the error message.
Definition Invalid.cpp:84
~InvalidUsername()
Destroy the InvalidUsername object.
Definition Invalid.cpp:82
const std::string myToString(bool value)
Converts a boolean value to its string representation.
Definition ToString.cpp:22