1use std::{error::Error, fmt::Display};
2
3#[derive(Debug)]
4pub enum ParseError {
5 MissingProgramName,
6 BadInternalState,
7 MalformedOption(String),
8 UnexpectedOption(String),
9 MissingValue(String),
10}
11
12impl Display for ParseError {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14 match self {
15 ParseError::MissingProgramName => {
16 write!(f, "missing expected first argument (program name)")
17 }
18 ParseError::BadInternalState => {
19 write!(f, "bad internal state, possibly bug in opts lib")
20 }
21 ParseError::MalformedOption(arg) => write!(f, "malformed option; got '{}'", arg),
22 ParseError::UnexpectedOption(arg) => write!(f, "unexpected option; got '{}'", arg),
23 ParseError::MissingValue(arg) => write!(f, "missinfg value for {}", arg),
24 }
25 }
26}
27
28impl Error for ParseError {}
29
30#[derive(Debug)]
31pub enum ValueError {
32 WrongOptionType,
33 ConversionError(String),
34}
35
36impl Display for ValueError {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 match self {
39 ValueError::WrongOptionType => write!(f, "wrong option type"),
40 ValueError::ConversionError(val) => {
41 write!(f, "error converting value '{}'", val)
42 }
43 }
44 }
45}
46
47impl Error for ValueError {}