SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1
/*
2
* SatNOGS-COMMS control library
3
*
4
* Copyright (C) 2021-2024, Libre Space Foundation <http://libre.space>
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*
19
* SPDX-License-Identifier: GNU General Public License v3.0 or later
20
*/
21
22
#pragma once
23
24
#include <cstdint>
25
#include <etl/error_handler.h>
26
#include <etl/string_stream.h>
27
#include <
satnogs-comms-lib/errno_extended.hpp
>
28
29
namespace
satnogs::comms::lib
30
{
31
62
class
exception
:
public
std::exception,
public
etl::exception
63
{
64
public
:
70
enum class
severity
: uint8_t
71
{
72
CATASTROPHIC
= 0,
73
CRITICAL
= 1,
74
MAJOR
= 2,
75
MINOR
= 3,
76
NONE
= 4
77
};
78
82
class
error_msg
83
{
84
public
:
85
const
char
*
verbose
;
87
const
char
*
terse
;
89
int32_t
error_num
;
93
};
94
102
exception
(
severity
sev,
const
char
*file,
int
lineno,
103
const
error_msg
&err_msg)
104
: std::
exception
(),
105
etl::
exception
(ETL_ERROR_TEXT(err_msg.verbose, err_msg.terse), file,
106
lineno),
107
m_severity(sev),
108
m_errno(err_msg.error_num)
109
{
110
}
111
121
void
122
to_string
(etl::string_stream &stream)
const
123
{
124
stream << etl::exception::what() <<
" | File: "
<< file_name() <<
":"
125
<< line_number()
126
<<
" | Severity: "
<<
static_cast<
int32_t
>
(m_severity)
127
<<
" | Error: "
<< m_errno;
128
}
129
138
void
139
to_string
(etl::istring &s)
const
140
{
141
etl::string_stream stream(s);
142
to_string
(stream);
143
}
144
145
const
char
*
146
what
() const noexcept
override
147
{
148
return
etl::exception::what();
149
}
150
151
int32_t
152
get_errno
()
const
153
{
154
return
m_errno;
155
}
156
164
severity
165
get_severity
()
const
166
{
167
return
m_severity;
168
}
169
170
private
:
171
const
severity
m_severity;
172
const
int32_t m_errno;
173
};
174
179
class
inval_arg_exception
:
public
exception
180
{
181
public
:
189
inval_arg_exception
(
severity
sev,
const
char
*file_name,
int
line)
190
:
exception
(sev, file_name, line,
191
error_msg
{
"Invalid argument"
,
"invalarg"
, EINVAL})
192
{
193
}
194
202
inval_arg_exception
(
const
char
*file_name,
int
line)
203
:
exception
(
severity
::
MINOR
, file_name, line,
204
error_msg
{
"Invalid argument"
,
"invalarg"
, EINVAL})
205
{
206
}
207
};
208
215
class
msg_too_long_exception
:
public
exception
216
{
217
public
:
218
msg_too_long_exception
(
const
char
*file_name,
int
line)
219
:
exception
(
exception
::
severity
::
MINOR
, file_name, line,
220
error_msg
{
"Message too long"
,
"msgbadsize"
, EMSGSIZE})
221
{
222
}
223
};
224
231
class
resource_unavailable_exception
:
public
exception
232
{
233
public
:
234
resource_unavailable_exception
(
const
char
*file_name,
int
line)
235
:
exception
(
236
exception
::
severity
::
MINOR
, file_name, line,
237
error_msg
{
"The resource you are trying to access is currently "
238
"unavailable"
,
239
"eagain"
, EAGAIN})
240
{
241
}
242
};
243
249
class
timeout_exception
:
public
exception
250
{
251
public
:
252
timeout_exception
(
const
char
*file_name,
int
line)
253
:
exception
(
exception
::
severity
::
MINOR
, file_name, line,
254
error_msg
{
"Timeout occurred"
,
"timeout"
, ETIMEDOUT})
255
{
256
}
257
};
258
260
261
}
/* namespace satnogs::comms::lib */
satnogs::comms::lib::exception::error_msg
A class representing error messages in the SatNOGS-COMMS system.
Definition
exception.hpp:83
satnogs::comms::lib::exception::error_msg::terse
const char * terse
Definition
exception.hpp:87
satnogs::comms::lib::exception::error_msg::verbose
const char * verbose
Definition
exception.hpp:85
satnogs::comms::lib::exception::error_msg::error_num
int32_t error_num
Definition
exception.hpp:89
satnogs::comms::lib::exception::severity
severity
Severity levels of exceptions.
Definition
exception.hpp:71
satnogs::comms::lib::exception::severity::MINOR
@ MINOR
Failure having minimal impact.
Definition
exception.hpp:75
satnogs::comms::lib::exception::severity::MAJOR
@ MAJOR
Failure causing minor mission degradation.
Definition
exception.hpp:74
satnogs::comms::lib::exception::severity::CATASTROPHIC
@ CATASTROPHIC
Failure causing loss of mission.
Definition
exception.hpp:72
satnogs::comms::lib::exception::severity::CRITICAL
@ CRITICAL
Failure causing mission degradation or significant damage.
Definition
exception.hpp:73
satnogs::comms::lib::exception::severity::NONE
@ NONE
No failure.
Definition
exception.hpp:76
satnogs::comms::lib::exception::exception
exception(severity sev, const char *file, int lineno, const error_msg &err_msg)
Constructor for the exception class.
Definition
exception.hpp:102
satnogs::comms::lib::exception::to_string
void to_string(etl::istring &s) const
Creates a string representation of the exception.
Definition
exception.hpp:139
satnogs::comms::lib::exception::get_severity
severity get_severity() const
Get error severity level as defined in FDIR.
Definition
exception.hpp:165
satnogs::comms::lib::exception::what
const char * what() const noexcept override
Definition
exception.hpp:146
satnogs::comms::lib::exception::to_string
void to_string(etl::string_stream &stream) const
Creates a string representation of the exception.
Definition
exception.hpp:122
satnogs::comms::lib::exception::get_errno
int32_t get_errno() const
Definition
exception.hpp:152
satnogs::comms::lib::inval_arg_exception::inval_arg_exception
inval_arg_exception(severity sev, const char *file_name, int line)
Invalid argument exception with a specified severity level.
Definition
exception.hpp:189
satnogs::comms::lib::inval_arg_exception::inval_arg_exception
inval_arg_exception(const char *file_name, int line)
Invalid argument exception with a exception::severity::MINOR severity.
Definition
exception.hpp:202
satnogs::comms::lib::msg_too_long_exception::msg_too_long_exception
msg_too_long_exception(const char *file_name, int line)
Definition
exception.hpp:218
satnogs::comms::lib::resource_unavailable_exception::resource_unavailable_exception
resource_unavailable_exception(const char *file_name, int line)
Definition
exception.hpp:234
satnogs::comms::lib::timeout_exception::timeout_exception
timeout_exception(const char *file_name, int line)
Definition
exception.hpp:252
errno_extended.hpp
Defines custom error codes for the SatNOGS-COMMS control library.
satnogs::comms::lib
Definition
ad8318.hpp:30
libsatnogs-comms
include
satnogs-comms-lib
exception.hpp
Generated by
1.17.0