atmosphere_core/error.rs
1//! Error Handling Module for Atmosphere
2//!
3//! This module defines the error handling mechanisms used throughout the Atmosphere framework. It
4//! provides a comprehensive `Error` type that encapsulates various kinds of errors that may occur
5//! during database operations, file IO, and other framework-related activities.
6//!
7//! The module simplifies error management by categorizing common error types and providing a
8//! unified interface for handling them. This approach enhances code readability and
9//! maintainability, especially in scenarios involving complex database interactions and
10//! operations.
11
12use miette::Diagnostic;
13use thiserror::Error;
14
15use crate::{BindError, query::QueryError};
16
17/// Errors that can occur within Atmosphere.
18///
19/// This enum encapsulates a range of errors including IO errors, query-related errors, binding
20/// errors, and others. It is designed to provide a unified error handling mechanism across
21/// different components of the framework.
22#[derive(Debug, Diagnostic, Error)]
23#[non_exhaustive]
24pub enum Error {
25 #[error("io")]
26 #[diagnostic(code(atmosphere::io))]
27 Io(#[from] std::io::Error),
28
29 #[error("query")]
30 #[diagnostic(transparent)]
31 Query(#[from] QueryError),
32
33 #[error("bind")]
34 #[diagnostic(transparent)]
35 Bind(#[from] BindError),
36
37 #[error("other")]
38 #[diagnostic(code(atmosphere::other))]
39 Other,
40
41 #[error("internal")]
42 #[diagnostic(code(atmosphere::internal))]
43 Internal,
44}
45
46/// A specialized `Result` type for use throughout the Atmosphere framework.
47///
48/// This type alias simplifies error handling by using the `Error` enum as the default error type.
49/// It is used as the return type for functions and methods within the framework, where errors are
50/// expected to be one of the variants defined in the `Error` enum.
51pub type Result<T> = std::result::Result<T, Error>;