67 lines
2.9 KiB
Rust
67 lines
2.9 KiB
Rust
//! This module provides a set of error types that can be used to handle various issues
|
|
//! with interacting with the Discord API or handling date-related tasks.
|
|
//!
|
|
//! The errors in this module are designed to provide detailed information about what
|
|
//! went wrong, making it easier to diagnose and fix problems.
|
|
|
|
#![allow(dead_code)]
|
|
use log::SetLoggerError;
|
|
use poise::serenity_prelude;
|
|
use thiserror::Error;
|
|
|
|
use crate::date::PartialDate;
|
|
|
|
// // Since the errors themselves are very verbose, this seemed like complete overkill
|
|
// #[allow(clippy::missing_docs_in_private_items)]
|
|
|
|
/// Global error struct for idlefox
|
|
///
|
|
/// This enum represents various errors that can occur when interacting with most of the section of the program
|
|
#[derive(Error, Debug)]
|
|
pub enum IdleError {
|
|
/// Error indicating a critical failure in the Discord API interaction
|
|
///
|
|
/// This error is raised when an unrecoverable issue occurs while interfacing with the Discord API.
|
|
/// It may be recoverable by retrying the request or seeking assistance from the API provider.
|
|
#[error("An unrecoverable error occurred during Discord API interaction")]
|
|
GenericApiFailure,
|
|
|
|
/// Error indicating an invalid date format or an invalid date (dec 32, feb 30, etc..)
|
|
///
|
|
/// This error is raised when a user-provided date string cannot be parsed into a valid [PartialDate].
|
|
#[error("An error happened while tring to make sense of the date {0:?}")]
|
|
InvalidDate(PartialDate),
|
|
|
|
/// Generic error indicating an unexpected issue during Discord API call processing
|
|
///
|
|
/// This error is raised when an unforeseen issue occurs while handling a Discord API request.
|
|
/// It may be recoverable by re-trying the request or seeking assistance from the API provider.
|
|
#[error("An unexpected error occurred during Discord API processing: {0}")]
|
|
ApiProcessingError(#[from] serenity_prelude::Error),
|
|
|
|
/// Error indicating an invalid date string
|
|
///
|
|
/// This error is raised when a user-provided date string cannot be parsed into a valid [PartialDate].
|
|
/// Notifying the user and asking for manual correction will likely be required
|
|
#[error("An error occured while parsing the date given {0:?}")]
|
|
InvalidDateParsing(nom::Err<nom::error::Error<Box<str>>>),
|
|
|
|
/// Error indicating an issue with logging initialization
|
|
///
|
|
/// This error is raised when a critical issue occurs during logging initialization.
|
|
/// It may indicate that the file reader is read-only, and manual intervention will be required to resolve the problem.
|
|
#[error("An error occurred while initializing the logger: {0}")]
|
|
LoggerInitFailure(#[from] SetLoggerError),
|
|
}
|
|
|
|
impl From<nom::Err<nom::error::Error<&str>>> for IdleError {
|
|
fn from(err: nom::Err<nom::error::Error<&str>>) -> Self {
|
|
Self::InvalidDateParsing(err.map_input(|input| input.into()))
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
// use super::*;
|
|
}
|