SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
satnogs::comms::error_handler Class Reference

Centralized Exception and Error Handling Utility. More...

#include <error_handler.hpp>

Public Member Functions

 error_handler (error_handler const &)=delete
void operator= (error_handler const &)=delete
void assert_error (const lib::exception &e)
 Logs error details and throws an exception with ETL_ASSERT().
void assert_error (bool condition, const lib::exception &e)
 Logs error details and throws an exception with ETL_ASSERT() based on the condition.
uint32_t hwinfo_reset_cause () const
 Retrieves the hardware reset cause from the MCU.
void handle (const lib::exception &e)
 Handles a lib::exception based on its severity.
void handle (const std::exception &e)
 Handles a generic exception.
void handle (const etl::exception &e)
 Handles an an etl::exception.
template<typename T>
void assert_error (const char *file, int line)
 Asserts an error with file and line number information.
template<typename T>
void assert_error (bool condition, const char *file, int line)
 Asserts an error based on a condition, with file and line information.
void system_reboot () const
 Instructs a system reboot.

Static Public Member Functions

static error_handlerget_instance ()
 Singleton access to the error_handler subsystem.

Protected Member Functions

 error_handler ()
 Constructs an error_handler instance.
template<typename T>
void log (const T &e) const

Detailed Description

Centralized Exception and Error Handling Utility.

The error_handler class serves as the core mechanism for managing exceptions, logging error details, and executing appropriate system-level actions, such as initiating reboots, based on the severity of encountered issues.

This class is designed to handle a range of error scenarios, enabling the system to respond gracefully to both minor operational disruptions and critical failures.

Key features include:

  • Logging the error message and file/line information for debugging.
  • Assertion mechanism to throw exception.
  • Severity-based error responses, ranging from logging warnings to system reboots.

Definition at line 52 of file error_handler.hpp.

Constructor & Destructor Documentation

◆ error_handler() [1/2]

satnogs::comms::error_handler::error_handler ( error_handler const & )
delete

◆ error_handler() [2/2]

satnogs::comms::error_handler::error_handler ( )
protected

Constructs an error_handler instance.

Warning
This constructor is exclusively invoked by error_handler::get_instance(), as error_handler follows the singleton design pattern. To obtain an instance of the error_handler class, one must use error_handler::get_instance().

The constructor invokes the private method get_reset_cause() to read and store the hardware reset cause from the MCU. This ensures the reset cause is captured and cleared upon system initialization.

Definition at line 173 of file error_handler.cpp.

Member Function Documentation

◆ assert_error() [1/4]

template<typename T>
void satnogs::comms::error_handler::assert_error ( bool condition,
const char * file,
int line )
inline

Asserts an error based on a condition, with file and line information.

This templated method creates an error object of type T using the provided file and line information, then triggers an assertion only if the condition is false.

Template Parameters
TThe type of exception.
Parameters
conditionThe condition to evaluate.
fileThe source file where the error occurred.
lineThe line number where the error occurred.

Definition at line 122 of file error_handler.hpp.

◆ assert_error() [2/4]

void satnogs::comms::error_handler::assert_error ( bool condition,
const lib::exception & e )

Logs error details and throws an exception with ETL_ASSERT() based on the condition.

Triggers if the condition is false.

Parameters
conditionThe condition to evaluate.
eThe exception object containing error info.

Definition at line 30 of file error_handler.cpp.

◆ assert_error() [3/4]

template<typename T>
void satnogs::comms::error_handler::assert_error ( const char * file,
int line )
inline

Asserts an error with file and line number information.

This templated method creates an error object of type T using the provided file and line information, then triggers an assertion.

Template Parameters
TThe type of exception to instantiate.
Parameters
fileThe source file where the error occurred.
lineThe line number where the error occurred.

Definition at line 101 of file error_handler.hpp.

◆ assert_error() [4/4]

void satnogs::comms::error_handler::assert_error ( const lib::exception & e)

Logs error details and throws an exception with ETL_ASSERT().

Parameters
eThe exception object containing error info.

Definition at line 15 of file error_handler.cpp.

◆ get_instance()

error_handler & satnogs::comms::error_handler::get_instance ( )
inlinestatic

Singleton access to the error_handler subsystem.

Returns
error_handler&

Definition at line 61 of file error_handler.hpp.

◆ handle() [1/3]

void satnogs::comms::error_handler::handle ( const etl::exception & e)

Handles an an etl::exception.

Based on the fact that all ETL containers may not cause a catastrophic error on failed operations on them, this handler justs logs the exception occurred.

Parameters
eThe exception to handle.

Definition at line 140 of file error_handler.cpp.

◆ handle() [2/3]

void satnogs::comms::error_handler::handle ( const lib::exception & e)

Handles a lib::exception based on its severity.

This method logs the given exception and responds to it according to its severity level:

Parameters
eThe exception to handle.

Definition at line 108 of file error_handler.cpp.

◆ handle() [3/3]

void satnogs::comms::error_handler::handle ( const std::exception & e)

Handles a generic exception.

Note
All exceptions that do not have as base the lib::exception are handled with scl::exception::severity::CATASTROPHIC severity level
Parameters
ethe exception to handle

Definition at line 155 of file error_handler.cpp.

◆ hwinfo_reset_cause()

uint32_t satnogs::comms::error_handler::hwinfo_reset_cause ( ) const

Retrieves the hardware reset cause from the MCU.

Returns
uint32_t The internal hardware reset cause value.

Definition at line 41 of file error_handler.cpp.

◆ log()

template<typename T>
void satnogs::comms::error_handler::log ( const T & e) const
inlineprotected

Definition at line 136 of file error_handler.hpp.

◆ operator=()

void satnogs::comms::error_handler::operator= ( error_handler const & )
delete

◆ system_reboot()

void satnogs::comms::error_handler::system_reboot ( ) const

Instructs a system reboot.

This method instructs the system to reboot. It first sleeps for a short period to allow any buffered logs to be flushed, then requests a cold software reboot. If the reboot fails, a watchdog is expected to take over.

Definition at line 79 of file error_handler.cpp.


The documentation for this class was generated from the following files: