Skip to main content

dockerfile_parser_rs/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum ParseError {
5    FileError(String),
6    InternalError(String),
7    MissingArgument(String),
8    SyntaxError(String),
9    UnknownInstruction(String),
10    WrongNumberOfArguments(String),
11}
12
13impl fmt::Display for ParseError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            Self::FileError(msg) => write!(f, "File error: {msg}"),
17            Self::InternalError(msg) => write!(f, "Internal error: {msg}"),
18            Self::MissingArgument(msg) => write!(f, "Missing argument: {msg}"),
19            Self::SyntaxError(msg) => write!(f, "Syntax error: {msg}"),
20            Self::UnknownInstruction(msg) => write!(f, "Unknown instruction: {msg}"),
21            Self::WrongNumberOfArguments(msg) => write!(f, "Wrong number of arguments: {msg}"),
22        }
23    }
24}