Skip to content

Implement core::error::Error for all error types #916

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

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

cmoylan
Copy link
Contributor

@cmoylan cmoylan commented Aug 10, 2023

Implemented core::error::Error and core::fmt::Display for all error types. Addresses #594

I'm fairly new to Rust so there might be some coding conventions I'm not familiar with. I tried to match the style of existing Display implementations. Any and all feedback is appreciated.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

f,
"{}",
match self {
Self::InvalidChar(_usize) => "invalid character",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For variants like this that contain extra info, I think we should go ahead and include that in the error message: write!(f, "invalid character at index {index}")

CHANGELOG.md Outdated
@@ -15,6 +15,7 @@
- `FileSystem::copy` is now more efficient for large files.
- `MpService::startup_all_aps` and `MpService::startup_this_ap` now accept an
optional `event` parameter to allow non-blocking operation.
- Added `core::error::Error` implementations to all error types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: period at end of sentence.

@@ -1278,6 +1287,15 @@ pub struct TftpError {
pub error_string: [u8; 127],
}

impl Display for TftpError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: can drop the core:: here since fmt is already imported

"{}",
match self {
Self::InvalidChar(_usize) => "invalid character",
Self::InteriorNul(_usize) => "encountered null character",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the interior null error, maybe something like "interior null character at index {index}", to clarify that it's specifically an interior null that is the problem (a trailing null is expected and required).

@phip1611
Copy link
Member

Thanks for the contribution, this is a good addition!
Please fix the nits that were addressed by Nicholas. Then, we're good to go!

@cmoylan cmoylan force-pushed the implement-error-trait branch from a35e64d to 4dc61a4 Compare August 15, 2023 02:34
Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thanks :)

@nicholasbishop nicholasbishop added this pull request to the merge queue Aug 16, 2023
Merged via the queue into rust-osdev:main with commit 708343b Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants