Skip to content

Implement Error trait for uefi::Error #587

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 5 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/msrv_toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
# Oldest nightly that currently works with `cargo xtask build`.
channel = "nightly-2022-08-08"
channel = "nightly-2022-08-25"
components = ["rust-src"]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Added `TryFrom<core::ffi::CStr>` implementation for `CStr8`.
- Added `Directory::read_entry_boxed` which works similar to `File::get_boxed_info`. This allows
easier iteration over the entries in a directory.
- Added an `core::error::Error` implementation for `Error` to ease
integration with error-handling crates.

## uefi-macros - [Unreleased]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ prerequisites for running the tests.
For instructions on how to create your own UEFI apps, see the [BUILDING.md](BUILDING.md) file.

The uefi-rs crates currently require some [unstable features].
The nightly MSRV is currently 2022-08-08.
The nightly MSRV is currently 2022-08-25.

[unstable features]: https://github.com/rust-osdev/uefi-rs/issues/452

Expand Down
1 change: 1 addition & 0 deletions uefi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#![feature(maybe_uninit_slice)]
#![feature(negative_impls)]
#![feature(ptr_metadata)]
#![feature(error_in_core)]
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in another PR, we're going to want to gate new unstable features behind an unstable feature in the UEFI crate: https://github.com/rust-osdev/uefi-rs/pull/584/files#r1031848552

However, we haven't merged in the new feature gate yet, so I think I'll go ahead and merge this PR, and update #590 to put this behind the unstable fate.

#![cfg_attr(feature = "alloc", feature(vec_into_raw_parts))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![no_std]
Expand Down
10 changes: 9 additions & 1 deletion uefi/src/result/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Status;
use core::fmt::Debug;
use core::fmt::{Debug, Display};

/// Errors emitted from UEFI entry point must propagate erronerous UEFI statuses,
/// and may optionally propagate additional entry point-specific data.
Expand Down Expand Up @@ -39,3 +39,11 @@ impl From<Status> for Error<()> {
Self { status, data: () }
}
}

impl<Data: Debug + Display> Display for Error<Data> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "UEFI Error {}: {}", self.status(), self.data())
}
}

impl<Data: Debug + Display> core::error::Error for Error<Data> {}
6 changes: 6 additions & 0 deletions uefi/src/result/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ impl From<Status> for Result<(), ()> {
}
}

impl core::fmt::Display for Status {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Debug::fmt(self, f)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down