Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on quick-error #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ version = "0.7.0"
authors = ["[email protected]"]

[dependencies]
quick-error = "2.0.0"
hostname = { version = "^0.3", optional = true }

[features]
Expand Down
90 changes: 55 additions & 35 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,62 @@ use std::str::{Utf8Error, from_utf8};

use {AddrParseError, Config, Network, Lookup, Family};

quick_error!{
/// Error while parsing resolv.conf file
#[derive(Debug)]
pub enum ParseError {
/// Error that may be returned when the string to parse contains invalid UTF-8 sequences
InvalidUtf8(line: usize, err: Utf8Error) {
display("bad unicode at line {}: {}", line, err)
source(err)
}
/// Error returned a value for a given directive is invalid.
/// This can also happen when the value is missing, if the directive requires a value.
InvalidValue(line: usize) {
display("directive at line {} is improperly formatted \
or contains invalid value", line)
}
/// Error returned when a value for a given option is invalid.
/// This can also happen when the value is missing, if the option requires a value.
InvalidOptionValue(line: usize) {
display("directive options at line {} contains invalid \
value of some option", line)
}
/// Error returned when a invalid option is found.
InvalidOption(line: usize) {
display("option at line {} is not recognized", line)
}
/// Error returned when a invalid directive is found.
InvalidDirective(line: usize) {
display("directive at line {} is not recognized", line)
}
/// Error returned when a value cannot be parsed an an IP address.
InvalidIp(line: usize, err: AddrParseError) {
display("directive at line {} contains invalid IP: {}", line, err)
/// Error while parsing resolv.conf file
#[derive(Debug)]
pub enum ParseError {
/// Error that may be returned when the string to parse contains invalid UTF-8 sequences
InvalidUtf8(usize, Utf8Error),
/// Error returned a value for a given directive is invalid.
/// This can also happen when the value is missing, if the directive requires a value.
InvalidValue(usize),
/// Error returned when a value for a given option is invalid.
/// This can also happen when the value is missing, if the option requires a value.
InvalidOptionValue(usize),
/// Error returned when a invalid option is found.
InvalidOption(usize),
/// Error returned when a invalid directive is found.
InvalidDirective(usize),
/// Error returned when a value cannot be parsed an an IP address.
InvalidIp(usize, AddrParseError),
/// Error returned when there is extra data at the end of a line.
ExtraData(usize),
}

impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
ParseError::InvalidUtf8(line, err) => {
write!(f, "bad unicode at line {}: {}", line, err)
}
ParseError::InvalidValue(line) => write!(
f,
"directive at line {} is improperly formatted or contains invalid value",
line
),
ParseError::InvalidOptionValue(line) => write!(
f,
"directive options at line {} contains invalid value of some option",
line
),
ParseError::InvalidOption(line) => {
write!(f, "option at line {} is not recognized", line)
}
ParseError::InvalidDirective(line) => {
write!(f, "directive at line {} is not recognized", line)
}
ParseError::InvalidIp(line, err) => {
write!(f, "directive at line {} contains invalid IP: {}", line, err)
}
ParseError::ExtraData(line) => write!(f, "extra data at the end of the line {}", line),
}
/// Error returned when there is extra data at the end of a line.
ExtraData(line: usize) {
display("extra data at the end of the line {}", line)
}
}

impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ParseError::InvalidUtf8(_, err) => Some(err),
_ => None,
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]

#[macro_use]
extern crate quick_error;
#[cfg(feature = "system")]
extern crate hostname;

Expand Down