tenebrous-dicebot/src/error.rs

97 lines
2.6 KiB
Rust
Raw Normal View History

use crate::config::ConfigError;
use crate::db::errors::DataError;
use crate::{commands::CommandError, migrator::migrations};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum BotError {
#[error("configuration error: {0}")]
ConfigurationError(#[from] ConfigError),
/// Sync token couldn't be found.
#[error("the sync token could not be retrieved")]
SyncTokenRequired,
#[error("could not retrieve device id")]
NoDeviceIdFound,
#[error("command error: {0}")]
CommandError(#[from] CommandError),
#[error("database error: {0}")]
DataError(#[from] DataError),
#[error("the message should not be processed because it failed validation")]
ShouldNotProcessError,
#[error("no cache directory found")]
NoCacheDirectoryError,
#[error("could not parse URL")]
UrlParseError(#[from] url::ParseError),
#[error("error in matrix state store: {0}")]
MatrixStateStoreError(#[from] matrix_sdk::StoreError),
#[error("uncategorized matrix SDK error")]
MatrixError(#[from] matrix_sdk::Error),
#[error("uncategorized matrix SDK base error")]
MatrixBaseError(#[from] matrix_sdk::BaseError),
#[error("future canceled")]
FutureCanceledError,
//de = deserialization
#[error("toml parsing error")]
TomlParsingError(#[from] toml::de::Error),
#[error("i/o error: {0}")]
IoError(#[from] std::io::Error),
Dice pool and command parser rewrite to prepare for user variables. This commit refactors the parsing and rolling for the dice pool system to prepare for support of user variables. The nom parser was dropped in favor of the easier-to-understand combine parser in most parts of the code. A breaking change was introduced into the dice pool syntax to allow for proper expressions and variables. The syntax is now "modifiers:pool-amount", e.g. "n:gnosis+8". The simple single-number syntax with no modifiers is also still understood. Dice pool expressions are translated into a Vec of "Amount" objects, stored by the DicePool struct. They have an operator (+ or -) and either a number or variable name. When the dice pool is rolled, this list of Amonuts are is collapsed into a single number that is rolled, as it was before the refactor. The following changes were made to the dice rolling code: - Store Vec<Amount> on DicePool instead of single number to roll. - New struct RolledDicePool to store result of a dice pool roll. - Remove Display trait from DicePool, move it over to RolledDicePool. - Separate extra dice pool info into DicePoolModifiers. - DicePoolModifiers is shared between DicePool and RolledDicePool. - Dice parsing and rolling now return standard Result objects. This commit does NOT enable support of actually using variables. Any dice pool roll containing a variable will result in an eror. The command parser was also rewritten to use combine and rely on the standard Result pattern.
2020-10-04 21:32:50 +00:00
#[error("dice parsing error: {0}")]
DiceParsingError(#[from] crate::parser::DiceParsingError),
#[error("command parsing error: {0}")]
CommandParsingError(#[from] crate::commands::parser::CommandParsingError),
Dice pool and command parser rewrite to prepare for user variables. This commit refactors the parsing and rolling for the dice pool system to prepare for support of user variables. The nom parser was dropped in favor of the easier-to-understand combine parser in most parts of the code. A breaking change was introduced into the dice pool syntax to allow for proper expressions and variables. The syntax is now "modifiers:pool-amount", e.g. "n:gnosis+8". The simple single-number syntax with no modifiers is also still understood. Dice pool expressions are translated into a Vec of "Amount" objects, stored by the DicePool struct. They have an operator (+ or -) and either a number or variable name. When the dice pool is rolled, this list of Amonuts are is collapsed into a single number that is rolled, as it was before the refactor. The following changes were made to the dice rolling code: - Store Vec<Amount> on DicePool instead of single number to roll. - New struct RolledDicePool to store result of a dice pool roll. - Remove Display trait from DicePool, move it over to RolledDicePool. - Separate extra dice pool info into DicePoolModifiers. - DicePoolModifiers is shared between DicePool and RolledDicePool. - Dice parsing and rolling now return standard Result objects. This commit does NOT enable support of actually using variables. Any dice pool roll containing a variable will result in an eror. The command parser was also rewritten to use combine and rely on the standard Result pattern.
2020-10-04 21:32:50 +00:00
#[error("dice rolling error: {0}")]
DiceRollingError(#[from] DiceRollingError),
#[error("variable parsing error: {0}")]
VariableParsingError(#[from] crate::variables::VariableParsingError),
Dice pool and command parser rewrite to prepare for user variables. This commit refactors the parsing and rolling for the dice pool system to prepare for support of user variables. The nom parser was dropped in favor of the easier-to-understand combine parser in most parts of the code. A breaking change was introduced into the dice pool syntax to allow for proper expressions and variables. The syntax is now "modifiers:pool-amount", e.g. "n:gnosis+8". The simple single-number syntax with no modifiers is also still understood. Dice pool expressions are translated into a Vec of "Amount" objects, stored by the DicePool struct. They have an operator (+ or -) and either a number or variable name. When the dice pool is rolled, this list of Amonuts are is collapsed into a single number that is rolled, as it was before the refactor. The following changes were made to the dice rolling code: - Store Vec<Amount> on DicePool instead of single number to roll. - New struct RolledDicePool to store result of a dice pool roll. - Remove Display trait from DicePool, move it over to RolledDicePool. - Separate extra dice pool info into DicePoolModifiers. - DicePoolModifiers is shared between DicePool and RolledDicePool. - Dice parsing and rolling now return standard Result objects. This commit does NOT enable support of actually using variables. Any dice pool roll containing a variable will result in an eror. The command parser was also rewritten to use combine and rely on the standard Result pattern.
2020-10-04 21:32:50 +00:00
#[error("legacy parsing error")]
NomParserError(nom::error::ErrorKind),
#[error("legacy parsing error: not enough data")]
NomParserIncomplete,
#[error("variables not yet supported")]
VariablesNotSupported,
#[error("database error")]
DatabaseError(#[from] sled::Error),
#[error("database migration error: {0}")]
SqliteError(#[from] crate::migrator::MigrationError),
#[error("too many commands or message was too large")]
MessageTooLarge,
2021-05-13 20:52:01 +00:00
#[error("could not convert to proper integer type")]
TryFromIntError(#[from] std::num::TryFromIntError),
}
#[derive(Error, Debug)]
pub enum DiceRollingError {
#[error("variable not found: {0}")]
VariableNotFound(String),
#[error("invalid amount")]
InvalidAmount,
#[error("dice pool expression too large")]
ExpressionTooLarge,
}