You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
1.9 KiB
113 lines
1.9 KiB
//! Argument related errors
|
|
use super::*;
|
|
use std::{
|
|
error,
|
|
fmt,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub enum ParseErrorKind
|
|
{
|
|
ExpectedArg(String),
|
|
UnknownOption(char),
|
|
UnknownOptionFor(char, char),
|
|
CannotCombine(char, char),
|
|
BadTail(char, String),
|
|
NotUnique(char),
|
|
ModeSet,
|
|
}
|
|
|
|
impl error::Error for ParseErrorKind{}
|
|
|
|
impl fmt::Display for ParseErrorKind
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
impl From<(String, ParseErrorKind)> for Error
|
|
{
|
|
#[inline] fn from((froms, fromk): (String, ParseErrorKind)) -> Self
|
|
{
|
|
Self::Parse(froms, fromk)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub enum ConstructError
|
|
{
|
|
AlreadyExists(String),
|
|
Resolve(resolve::Error),
|
|
}
|
|
impl error::Error for ConstructError
|
|
{
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
Some(match self {
|
|
Self::Resolve(res) => res,
|
|
_=> return None,
|
|
})
|
|
}
|
|
}
|
|
impl fmt::Display for ConstructError
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
match self {
|
|
_ => write!(f, "unknown error"),
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub enum Error {
|
|
Parse(String, ParseErrorKind),
|
|
|
|
Unknown,
|
|
AtomInternal,
|
|
}
|
|
impl error::Error for Error
|
|
{
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
Some(match &self {
|
|
Error::Parse(_, parse) => parse,
|
|
_=> return None,
|
|
})
|
|
}
|
|
}
|
|
impl fmt::Display for Error
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
match self {
|
|
Error::AtomInternal => unreachable!("This should've been handled."),
|
|
_ => write!(f, "unknown error"),
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error
|
|
{
|
|
#[inline] fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self
|
|
{
|
|
Self::AtomInternal
|
|
}
|
|
}
|
|
|
|
|
|
impl From<resolve::Error> for ConstructError
|
|
{
|
|
#[inline] fn from(from: resolve::Error) -> Self
|
|
{
|
|
Self::Resolve(from)
|
|
}
|
|
}
|