Skip to content

Commit

Permalink
feat: change parsing error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Dec 19, 2024
1 parent 18251a6 commit 57b9b2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/debugger/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ impl Command {
let mut expected_args = 0;

let command = match name {
CommandName::Help => Self::Help,
// Allow trailing arguments
CommandName::Help => return Ok(Self::Help),

CommandName::Continue => Self::Continue,
CommandName::Finish => Self::Finish,
CommandName::Exit => Self::Exit,
Expand Down Expand Up @@ -178,6 +180,7 @@ impl Command {
argument: "instruction",
});
}
// Don't return `Err` for invalid argument count, as this shouldn't happen
debug_assert!(
iter.expect_end_of_command(0, 0).is_ok(),
"no more arguments should exist",
Expand Down
10 changes: 6 additions & 4 deletions src/debugger/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl fmt::Display for CommandError {
}

Self::InvalidArgument { name, error } => {
write!(f, "In command `{}`: ", name)?;

match error {
ArgumentError::MissingArgument { argument, expected } => {
write!(f, "Missing argument `{}` (expected {})", argument, expected)?;
Expand All @@ -84,9 +86,11 @@ impl fmt::Display for CommandError {
}

ArgumentError::InvalidValue { argument, error } => {
write!(f, "For argument `{}`: ", argument)?;

match error {
ValueError::WrongArgumentType {} => {
write!(f, "Invalid type")?;
write!(f, "Incorrect value type")?;
}
ValueError::MalformedArgument {} => {
write!(f, "Malformed argument")?;
Expand All @@ -101,12 +105,10 @@ impl fmt::Display for CommandError {
write!(f, "Integer argument too large")?;
}
}

write!(f, " for argument `{}`", argument)?;
}
}

write!(f, " for command `{}`", name)
Ok(())
}
}
}
Expand Down

0 comments on commit 57b9b2c

Please sign in to comment.