Function default_callback

Source
pub fn default_callback(err: TracebackError)
Expand description

§Default Traceback Error Callback

The default_callback function is a built-in error handling callback used when TRACEBACK_ERROR_CALLBACK is set to None. This callback is responsible for handling and reporting TracebackError instances in a default manner.

§Behavior

When a TracebackError goes out of scope and TRACEBACK_ERROR_CALLBACK is not set to a custom callback, the default_callback function is used. This function performs the following actions:

  1. Retrieves the current time in UTC and creates a timestamp string.
  2. Checks if the “errors” folder exists and creates it if it doesn’t.
  3. Generates a unique filename based on the current timestamp.
  4. Writes the error information in JSON format to a file with the generated filename in the “errors” folder.
  5. Logs any encountered errors during the above steps.

This default behavior ensures that unhandled errors are captured, timestamped, and saved as JSON files for later analysis.

§Usage

Typically, you don’t need to call the default_callback function directly. Instead, it is automatically used as the error handler when TRACEBACK_ERROR_CALLBACK is not set to a custom callback.

Example of using the default behavior when TRACEBACK_ERROR_CALLBACK is not set:

// No custom callback set, so the default_callback will be used
traceback_error::set_traceback!(None);

// Any TracebackErrors will now be handled by the default_callback when dropped

To customize error handling, you can set a custom callback using the set_traceback! macro as shown in the documentation for TRACEBACK_ERROR_CALLBACK.