aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2020-10-13 01:09:18 -0700
committerRichard Walters <rwalters@digitalstirling.com>2020-10-13 01:09:18 -0700
commitdc2a011598f4aa9e9de927333e467e623276d5ec (patch)
tree4b5c71634af516cdc96c512f28a02370d48c25b3 /src/error.rs
parent4accf8c296ef7a1f6bd10a90b7a06b3b499ccda6 (diff)
Rust refactoring
* Move Context, Error, and character classes to their own modules. * Move host/port parsing and IP address validation to their own modules, and break the code up into different functions to process their state machines.
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..e37a02f
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,40 @@
+#![warn(clippy::pedantic)]
+
+use super::context::Context;
+
+#[derive(Debug, Clone, thiserror::Error, PartialEq)]
+pub enum Error {
+ #[error("URI contains non-UTF8 sequences")]
+ CannotExpressAsUtf8(#[from] std::string::FromUtf8Error),
+
+ #[error("scheme expected but missing")]
+ EmptyScheme,
+
+ #[error("illegal character in {0}")]
+ IllegalCharacter(Context),
+
+ #[error("illegal percent encoding")]
+ IllegalPercentEncoding,
+
+ #[error("illegal port number")]
+ IllegalPortNumber(#[source] std::num::ParseIntError),
+
+ #[error("octet group expected")]
+ InvalidDecimalOctet,
+
+ #[error("too few address parts")]
+ TooFewAddressParts,
+
+ #[error("too many address parts")]
+ TooManyAddressParts,
+
+ #[error("too many digits in IPv6 address part")]
+ TooManyDigits,
+
+ #[error("too many double-colons in IPv6 address")]
+ TooManyDoubleColons,
+
+ #[error("truncated host")]
+ TruncatedHost,
+}
+