summary refs log tree commit diff stats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..74ba2fd
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,42 @@
+// Copyright (c) 2021 Soni L.
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+// Documentation and comments licensed under CC BY-SA 4.0.
+
+//! Built-in error traits.
+//!
+//! Iosonism uses a trait-based approach because that's just far more flexible.
+
+use ::std::error::Error as StdError;
+
+use crate::strcursor::StringReader;
+
+/// Built-in `StringReader` errors.
+pub trait ReadError<'a, C: StringReader<'a>>: Sized + StdError {
+    /// Creates an error that indicates an invalid integer was found.
+    fn invalid_integer(context: &C, from: &str) -> Self;
+    /// Creates an error that indicates an integer was expected.
+    fn expected_integer(context: &C) -> Self;
+    /// Creates an error that indicates an invalid float was found.
+    fn invalid_float(context: &C, from: &str) -> Self;
+    /// Creates an error that indicates a float was expected.
+    fn expected_float(context: &C) -> Self;
+    /// Creates an error that indicates an invalid bool was found.
+    fn invalid_bool(context: &C, from: &str) -> Self;
+    /// Creates an error that indicates a bool was expected.
+    fn expected_bool(context: &C) -> Self;
+    /// Creates an error that indicates the start of a quote was expected.
+    fn expected_start_of_quote(context: &C) -> Self;
+    /// Creates an error that indicates the end of a quote was expected.
+    fn expected_end_of_quote(context: &C) -> Self;
+    /// Creates an error that indicates an invalid escape was found.
+    fn invalid_escape(context: &C, from: &str) -> Self;
+    /// Creates an error that indicates a symbol was expected.
+    fn expected_symbol(context: &C, from: &str) -> Self;
+}
+
+/// Built-in errors for `IntegerArgumentType` and `FloatArgumentType`.
+pub trait RangeError<'a, C: StringReader<'a>, T, R>: Sized + StdError {
+    /// Creates an error that indicates a value was outside the required bounds.
+    fn value_not_in_range(context: &C, from: &T, range: &R) -> Self;
+}