Skip to content
Merged
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
41 changes: 40 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

use indextree::NodeId;

use crate::pipe::PipeError;

#[derive(Debug)]
pub enum Error {
Parser(ParserError),
EditConfig(yang4::Error),
ValidateConfig(yang4::Error),
Callback(String),
Callback(CallbackError),
Backend(tonic::Status),
Pipe(PipeError),
}

#[derive(Debug)]
Expand All @@ -22,6 +25,12 @@ pub enum ParserError {
Ambiguous(Vec<NodeId>),
}

#[derive(Debug)]
pub enum CallbackError {
BrokenPipe,
Other(String),
}

// ===== impl Error =====

impl std::fmt::Display for Error {
Expand All @@ -40,6 +49,9 @@ impl std::fmt::Display for Error {
Error::Backend(error) => {
write!(f, "{}", error)
}
Error::Pipe(error) => {
write!(f, "{}", error)
}
}
}
}
Expand All @@ -61,3 +73,30 @@ impl std::fmt::Display for ParserError {
}

impl std::error::Error for ParserError {}

// ===== impl CallbackError =====

impl std::fmt::Display for CallbackError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CallbackError::BrokenPipe => write!(f, "broken pipe"),
CallbackError::Other(msg) => write!(f, "{}", msg),
}
}
}

impl From<String> for CallbackError {
fn from(s: String) -> Self {
CallbackError::Other(s)
}
}

impl From<std::io::Error> for CallbackError {
fn from(e: std::io::Error) -> Self {
if e.kind() == std::io::ErrorKind::BrokenPipe {
CallbackError::BrokenPipe
} else {
CallbackError::Other(e.to_string())
}
}
}
Loading
Loading