Skip to content

uefi-services: Change panic handler log message. #526

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
Oct 11, 2022

Conversation

raccog
Copy link
Contributor

@raccog raccog commented Oct 11, 2022

The panic handler now displays its log message using println! instead of error!. The message prefix is altered from [ERROR] to [PANIC]. The extraneous filename and line number printed by error! are also removed from the log message.

Previously, the panic handler in uefi-services would use error! to print a log message. By using error!, the log message would also include the file name and line number of the panic handler function. As the file name and line number where the panic originated from are logged using the PanicInfo struct, this information is not necessary. By printing the log message with println! instead of error! this unnecessary information can be removed.

Example

I temporarily added a panic call to the uefi test runner to show the panic log messages:

    // ...

    // uefi-test-runner/src/main.rs@21
    // Initialize utilities (logging, memory allocation...)
    uefi_services::init(&mut st).expect("Failed to initialize utilities");

    // test a call to panic
    panic!("Here is a panic!");

    // unit tests here

    // output firmware-vendor (CStr16 to Rust string)
    let mut buf = String::new();

    // ...

Log message before this commit:

[ERROR]: uefi-services/src/lib.rs@184: panicked at 'Here is a panic!', uefi-test-runner/src/main.rs:25:5

Log message after commit:

[PANIC]: panicked at 'Here is a panic!', uefi-test-runner/src/main.rs:25:5

Checklist

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

The panic handler now displays its log message using `println!` instead
of `error!`. The message prefix is altered from [ERROR] to [PANIC].
The extraneous filename and line number printed by `error!` are also
removed from the log message.
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 merged commit 5939e57 into rust-osdev:main Oct 11, 2022
nicholasbishop added a commit that referenced this pull request Oct 11, 2022
nicholasbishop added a commit that referenced this pull request Oct 11, 2022
Fixup for #526. We still use
one logging macro, but only if certain `cfg` attributes match, so call
it by the full path of `log::error`.
@raccog
Copy link
Contributor Author

raccog commented Oct 11, 2022

LGTM, thanks :)

Glad to contribute! :)

@phip1611
Copy link
Member

Very nice, thanks for the contribution!

@raccog raccog deleted the panic-handler-log branch December 18, 2022 20:39
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