-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from brson/errors
Implement StdError for Error
- Loading branch information
Showing
3 changed files
with
50 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::error::Error as StdError; | ||
use std::io::{Error as IOError, ErrorKind}; | ||
|
||
#[derive(Debug, PartialEq, Clone, Copy, Eq, Display)] | ||
pub enum Error { | ||
#[display(fmt = "parse error")] | ||
ParseError, | ||
#[display(fmt = "unaligned page access")] | ||
Unaligned, | ||
#[display(fmt = "out of bound access")] | ||
OutOfBound, | ||
#[display(fmt = "max cycles exceeded")] | ||
InvalidCycles, | ||
#[display(fmt = "invalid instruction {}", "_0")] | ||
InvalidInstruction(u32), | ||
#[display(fmt = "invalid syscall {}", "_0")] | ||
InvalidEcall(u64), | ||
#[display(fmt = "invalid elf")] | ||
InvalidElfBits, | ||
#[display(fmt = "invalid operand {}", "_0")] | ||
InvalidOp(u8), | ||
#[display(fmt = "I/O error: {:?}", "_0")] | ||
IO(ErrorKind), | ||
#[display(fmt = "dynasm error {}", "_0")] | ||
Dynasm(i32), | ||
#[display(fmt = "assembly error {}", "_0")] | ||
Asm(u8), | ||
#[display(fmt = "limit reached")] // FIXME: Distinguish which limit | ||
LimitReached, | ||
#[display(fmt = "invalid permission")] // FIXME: Distinguish which permission | ||
InvalidPermission, | ||
#[display(fmt = "unexpected error")] | ||
Unexpected, | ||
#[display(fmt = "unimplemented")] | ||
Unimplemented, | ||
} | ||
|
||
impl StdError for Error { } | ||
|
||
impl From<IOError> for Error { | ||
fn from(error: IOError) -> Self { | ||
Error::IO(error.kind()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters