Skip to content

Commit

Permalink
Add context to Error::NoFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Nov 25, 2023
1 parent 465fa3d commit a97dcc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
use std::error;
use std::fmt;
use std::io;
use std::path::PathBuf;

use nom::Err;

#[derive(Debug)]
pub enum Error {
IoError(io::Error),
NoFilename,
NoFilename(PathBuf),
ParsingIncomplete,
ParsingError(Vec<u8>, ParsingErrorKind),
DecodeError(Vec<u8>),
Expand All @@ -53,8 +54,8 @@ impl From<io::Error> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::IoError(ref x) => x.fmt(f),
Error::NoFilename => write!(f, "The plugin path has no filename part"),
Error::IoError(x) => x.fmt(f),
Error::NoFilename(path) => write!(f, "The plugin path {path:?} has no filename part"),
Error::ParsingIncomplete => write!(f, "More input was expected by the plugin parser"),
Error::ParsingError(input, kind) => write!(
f,
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Plugin {

pub fn parse(&mut self, input: &[u8], load_header_only: bool) -> Result<(), Error> {
match self.filename() {
None => Err(Error::NoFilename),
None => Err(Error::NoFilename(self.path.clone())),
Some(filename) => {
self.data = parse_plugin(input, self.game_id, &filename, load_header_only)?.1;

Expand All @@ -123,7 +123,7 @@ impl Plugin {
expected_header_type: &'static [u8],
) -> Result<(), Error> {
match self.filename() {
None => Err(Error::NoFilename),
None => Err(Error::NoFilename(self.path.clone())),
Some(filename) => {
self.data = read_plugin(
&mut reader,
Expand Down

0 comments on commit a97dcc0

Please sign in to comment.