Skip to content
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

logger: don't panic in the panic handler #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unleashed
Copy link

This avoids a potential double-panic in the panic handler if the logging status code is not recognised.

Signed-off-by: Alejandro Martinez Ruiz <[email protected]>
Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

This is technically correct (good catch!), but looking at the code, I cannot see how proxy_log could panic here. Did you run into this double-panic?

@@ -21,12 +21,20 @@ extern "C" {
fn proxy_log(level: LogLevel, message_data: *const u8, message_size: usize) -> Status;
}

// Useful for the panic hook to avoid a double-panic.
#[inline]
pub(crate) fn log_nopanic(level: LogLevel, message: &str) -> Result<Status, Status> {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for using Result<Status, Status> instead of Result<(), Status> like rest of the SDK?

Copy link
Author

Choose a reason for hiding this comment

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

Just leaving the decision about what to do with the Status to the callers out of habit. Since this fn is private to this crate it won't show as part of the SDK to users, and this allows for callers to have more flexibility to make that decision or be extended based on this value without needing to modify this fn.

@unleashed
Copy link
Author

No, I didn't run into it. I just wanted to protect against the possibility that changes happen elsewhere and a new code path opens inadvertently that allows this to happen.

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.

2 participants