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

Print more information for TLS errors #143

Merged
merged 2 commits into from
Jul 12, 2023
Merged

Conversation

ljrk0
Copy link
Contributor

@ljrk0 ljrk0 commented Jul 11, 2023

The aatxe/irc crate defines a crate-wide Error enum in irc/src/error.rs, wrapping different errors from various kinds of sources, such as TLS errors by tls-native. When .to_string() is invoked on such an enum, the error message using #[error("...")] is displayed. However, they wrap the actual Tls error enum inside with its own .to_string() function. In case of such errors, also include this information in our error message which is much more helpful for debugging.

image

Note that perhaps it'd be better to fix this upstream, it seems that the macro can at least also access fields from the enum, as seen here: https://github.com/aatxe/irc/blob/develop/src/error.rs#L76. Maybe something like

#[error("a TLS error occured: {}", tlserror)

with a corresponding field in the enum upstream would work, but my Rust foo is quite limited.

ljrk0 added a commit to ljrk0/irc that referenced this pull request Jul 11, 2023
When `.to_string()` is invoked on a the crate-wide Error enum,
the error message using #[error("...")] is displayed.
Some of those wrapped internal enums also contain, possibly more
helpful, error messages.  This will include the string gathered by
`.to_string()` from the encapsulated enum in the main error message.

See also
squidowl/halloy#143
@ljrk0
Copy link
Contributor Author

ljrk0 commented Jul 11, 2023

I've created an upstream PR as the code was much more easy than anticipated :)

@tarkah
Copy link
Member

tarkah commented Jul 11, 2023

Thanks for opening the PR!

It's idiomatic to not expose all nested error context in the Display implementation at each level. It's up to the consumer to decide if they want to dig into this context more, and if so, we can easily pattern match for the Error::Tls variant and print it's inner error.

I'd prefer to see the original approach vs having the maintainer pollute the top-level error display with all context, which may not be suitable for all use-cases of handling this error.

So without changing upstream, a good solution might be:

let error = match e {
  irc::Error::Tls(e) => format!("a TLS error occurred: {e}"),
  _ => e.to_string(),
};

@ljrk0
Copy link
Contributor Author

ljrk0 commented Jul 11, 2023

Thank you for your comment & time!

Ah, I see – I was just mirroring what other errors in the irc crate do, but I'm a noob when it comes to app design :) From what I can understand, you propose having the "complete" error in the log and the "top level" error in the UI? That would definitely work for me, especially given those TLS errors often even being multiline.

@tarkah
Copy link
Member

tarkah commented Jul 11, 2023

Thank you for your comment & time!

Ah, I see – I was just mirroring what other errors in the irc crate do, but I'm a noob when it comes to app design :) From what I can understand, you propose having the "complete" error in the log and the "top level" error in the UI? That would definitely work for me, especially given those TLS errors often even being multiline.

No problem! I think it's fine to use that new error string in both places. I think it'd be helpful to see it in the UI buffer since it's probably a common error where the context might help.

data/src/stream.rs Outdated Show resolved Hide resolved
The aatxe/irc crate defines a crate-wide Error enum in irc/src/error.rs,
wrapping different errors from various kinds of sources, such as
TLS errors by tls-native.  When `.to_string()` is invoked on such an
enum, the error message using `#[error("...")]` is displayed.  However,
they wrap the actual Tls error enum inside with its own `.to_string()`
function.  In case of such errors, also include this information in our
error message which is much more helpful for debugging.
@ljrk0 ljrk0 force-pushed the verbose_tls_error branch from 5dba4eb to 2dc146f Compare July 12, 2023 08:12
@ljrk0
Copy link
Contributor Author

ljrk0 commented Jul 12, 2023

Awesome, thanks for the feedback, I've forced-pushed your requested changes and tested the PR, it works well!

@tarkah
Copy link
Member

tarkah commented Jul 12, 2023

@ljrk0 Looks great, thanks for the contribution 🎉

@tarkah tarkah merged commit caa024d into squidowl:main Jul 12, 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.

2 participants