-
Notifications
You must be signed in to change notification settings - Fork 143
TryFrom implementation for ExceptionVector #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for your contribution!
Let's use a simple error type that wraps the invalid u8. Feel free to use x86_64/src/instructions/tlb.rs Lines 78 to 88 in 323d46c
|
Made Error as enum for more details |
src/structures/idt.rs
Outdated
impl fmt::Display for InvalidExceptionVectorNumber { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
InvalidExceptionVectorNumber::IsCoprocessorSegmentOverrun(exception_vector_number) => { | ||
write!(f, "{exception_vector_number} cannot be a valid exception vector number because the Coprocessor Segment Overrun exception is handled as part of the General Protection Fault") | ||
} | ||
InvalidExceptionVectorNumber::Reserved(exception_vector_number) => { | ||
write!(f, "{exception_vector_number} cannot be a valid exception vector number because it is reserved") | ||
} | ||
InvalidExceptionVectorNumber::NotException(exception_vector_number) => { | ||
write!(f, "{exception_vector_number} cannot be a valid exception vector number because only the first 32 numbers can be exception numbers") | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly a matter of opinion, but the error messages seem too lengthy to me. Let's just print "{} is not a valid exception vector"
in all cases and let's also use a struct instead of an enum. It shouldn't be difficult for the user to figure out what went wrong in each case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Sorry for the delay.
I rebased this PR onto the lastest master branch to fix CI. |
There is currently no way to create an instance of idt::ExceptionVector having an interrupt number. At the same time it would be convenient for the user to use this enum to handle interrupts.
As for the implementation, I couldn't think of what type of error it should return.