aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/exceptions
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-brigadier/src/exceptions')
-rw-r--r--azalea-brigadier/src/exceptions/builtin_exceptions.rs153
-rw-r--r--azalea-brigadier/src/exceptions/command_syntax_exception.rs94
-rw-r--r--azalea-brigadier/src/exceptions/mod.rs5
3 files changed, 0 insertions, 252 deletions
diff --git a/azalea-brigadier/src/exceptions/builtin_exceptions.rs b/azalea-brigadier/src/exceptions/builtin_exceptions.rs
deleted file mode 100644
index bf2072c1..00000000
--- a/azalea-brigadier/src/exceptions/builtin_exceptions.rs
+++ /dev/null
@@ -1,153 +0,0 @@
-use std::fmt;
-
-use super::command_syntax_exception::CommandSyntaxException;
-use crate::string_reader::StringReader;
-
-#[derive(Clone, PartialEq)]
-pub enum BuiltInExceptions {
- DoubleTooSmall { found: f64, min: f64 },
- DoubleTooBig { found: f64, max: f64 },
-
- FloatTooSmall { found: f32, min: f32 },
- FloatTooBig { found: f32, max: f32 },
-
- IntegerTooSmall { found: i32, min: i32 },
- IntegerTooBig { found: i32, max: i32 },
-
- LongTooSmall { found: i64, min: i64 },
- LongTooBig { found: i64, max: i64 },
-
- LiteralIncorrect { expected: String },
-
- ReaderExpectedStartOfQuote,
- ReaderExpectedEndOfQuote,
- ReaderInvalidEscape { character: char },
- ReaderInvalidBool { value: String },
- ReaderInvalidInt { value: String },
- ReaderExpectedInt,
- ReaderInvalidLong { value: String },
- ReaderExpectedLong,
- ReaderInvalidDouble { value: String },
- ReaderExpectedDouble,
- ReaderInvalidFloat { value: String },
- ReaderExpectedFloat,
- ReaderExpectedBool,
- ReaderExpectedSymbol { symbol: char },
-
- DispatcherUnknownCommand,
- DispatcherUnknownArgument,
- DispatcherExpectedArgumentSeparator,
- DispatcherParseException { message: String },
-}
-
-impl fmt::Debug for BuiltInExceptions {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- BuiltInExceptions::DoubleTooSmall { found, min } => {
- write!(f, "Double must not be less than {min}, found {found}")
- }
- BuiltInExceptions::DoubleTooBig { found, max } => {
- write!(f, "Double must not be more than {max}, found {found}")
- }
-
- BuiltInExceptions::FloatTooSmall { found, min } => {
- write!(f, "Float must not be less than {min}, found {found}")
- }
- BuiltInExceptions::FloatTooBig { found, max } => {
- write!(f, "Float must not be more than {max}, found {found}")
- }
-
- BuiltInExceptions::IntegerTooSmall { found, min } => {
- write!(f, "Integer must not be less than {min}, found {found}")
- }
- BuiltInExceptions::IntegerTooBig { found, max } => {
- write!(f, "Integer must not be more than {max}, found {found}")
- }
-
- BuiltInExceptions::LongTooSmall { found, min } => {
- write!(f, "Long must not be less than {min}, found {found}")
- }
- BuiltInExceptions::LongTooBig { found, max } => {
- write!(f, "Long must not be more than {max}, found {found}")
- }
-
- BuiltInExceptions::LiteralIncorrect { expected } => {
- write!(f, "Expected literal {expected}")
- }
-
- BuiltInExceptions::ReaderExpectedStartOfQuote => {
- write!(f, "Expected quote to start a string")
- }
- BuiltInExceptions::ReaderExpectedEndOfQuote => {
- write!(f, "Unclosed quoted string")
- }
- BuiltInExceptions::ReaderInvalidEscape { character } => {
- write!(f, "Invalid escape sequence '{character}' in quoted string")
- }
- BuiltInExceptions::ReaderInvalidBool { value } => {
- write!(
- f,
- "Invalid bool, expected true or false but found '{value}'"
- )
- }
- BuiltInExceptions::ReaderInvalidInt { value } => {
- write!(f, "Invalid Integer '{value}'")
- }
- BuiltInExceptions::ReaderExpectedInt => {
- write!(f, "Expected Integer")
- }
- BuiltInExceptions::ReaderInvalidLong { value } => {
- write!(f, "Invalid long '{value}'")
- }
- BuiltInExceptions::ReaderExpectedLong => {
- write!(f, "Expected long")
- }
- BuiltInExceptions::ReaderInvalidDouble { value } => {
- write!(f, "Invalid double '{value}'")
- }
- BuiltInExceptions::ReaderExpectedDouble => {
- write!(f, "Expected double")
- }
- BuiltInExceptions::ReaderInvalidFloat { value } => {
- write!(f, "Invalid Float '{value}'")
- }
- BuiltInExceptions::ReaderExpectedFloat => {
- write!(f, "Expected Float")
- }
- BuiltInExceptions::ReaderExpectedBool => {
- write!(f, "Expected bool")
- }
- BuiltInExceptions::ReaderExpectedSymbol { symbol } => {
- write!(f, "Expected '{symbol}'")
- }
-
- BuiltInExceptions::DispatcherUnknownCommand => {
- write!(f, "Unknown command")
- }
- BuiltInExceptions::DispatcherUnknownArgument => {
- write!(f, "Incorrect argument for command")
- }
- BuiltInExceptions::DispatcherExpectedArgumentSeparator => {
- write!(
- f,
- "Expected whitespace to end one argument, but found trailing data"
- )
- }
- BuiltInExceptions::DispatcherParseException { message } => {
- write!(f, "Could not parse command: {message}")
- }
- }
- }
-}
-
-impl BuiltInExceptions {
- pub fn create(self) -> CommandSyntaxException {
- let message = format!("{self:?}");
- CommandSyntaxException::create(self, message)
- }
-
- pub fn create_with_context(self, reader: &StringReader) -> CommandSyntaxException {
- let message = format!("{self:?}");
- CommandSyntaxException::new(self, message, reader.string(), reader.cursor())
- }
-}
diff --git a/azalea-brigadier/src/exceptions/command_syntax_exception.rs b/azalea-brigadier/src/exceptions/command_syntax_exception.rs
deleted file mode 100644
index c9b8134f..00000000
--- a/azalea-brigadier/src/exceptions/command_syntax_exception.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use std::{
- cmp,
- fmt::{self, Write},
-};
-
-use super::builtin_exceptions::BuiltInExceptions;
-
-#[derive(Clone, PartialEq)]
-pub struct CommandSyntaxException {
- pub type_: BuiltInExceptions,
- message: String,
- input: Option<String>,
- cursor: Option<usize>,
-}
-
-const CONTEXT_AMOUNT: usize = 10;
-
-impl CommandSyntaxException {
- pub fn new(type_: BuiltInExceptions, message: String, input: &str, cursor: usize) -> Self {
- Self {
- type_,
- message,
- input: Some(input.to_string()),
- cursor: Some(cursor),
- }
- }
-
- pub fn create(type_: BuiltInExceptions, message: String) -> Self {
- Self {
- type_,
- message,
- input: None,
- cursor: None,
- }
- }
-
- pub fn message(&self) -> String {
- let mut message = self.message.clone();
- let context = self.context();
- if let Some(context) = context {
- write!(
- message,
- " at position {}: {}",
- self.cursor.unwrap_or(usize::MAX),
- context
- )
- .unwrap();
- }
- message
- }
-
- pub fn raw_message(&self) -> &String {
- &self.message
- }
-
- pub fn context(&self) -> Option<String> {
- if let Some(input) = &self.input
- && let Some(cursor) = self.cursor
- {
- let mut builder = String::new();
- let cursor = cmp::min(input.len(), cursor);
-
- if cursor > CONTEXT_AMOUNT {
- builder.push_str("...");
- }
-
- builder.push_str(
- &input[(cmp::max(0, cursor as isize - CONTEXT_AMOUNT as isize) as usize)..cursor],
- );
- builder.push_str("<--[HERE]");
-
- return Some(builder);
- }
- None
- }
-
- pub fn get_type(&self) -> &BuiltInExceptions {
- &self.type_
- }
-
- pub fn input(&self) -> &Option<String> {
- &self.input
- }
-
- pub fn cursor(&self) -> Option<usize> {
- self.cursor
- }
-}
-
-impl fmt::Debug for CommandSyntaxException {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.message())
- }
-}
diff --git a/azalea-brigadier/src/exceptions/mod.rs b/azalea-brigadier/src/exceptions/mod.rs
deleted file mode 100644
index 6b9c8d62..00000000
--- a/azalea-brigadier/src/exceptions/mod.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-mod builtin_exceptions;
-mod command_syntax_exception;
-
-pub use builtin_exceptions::BuiltInExceptions;
-pub use command_syntax_exception::CommandSyntaxException;