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

sshforwarding: exit on ssh errors without printing any further errors #9

Merged
merged 3 commits into from
Oct 25, 2024

Conversation

mdibaiee
Copy link
Member

@mdibaiee mdibaiee commented Oct 24, 2024

This will allow us to give the SSH client's error directly to the user as the last error.

Example output:
image

src/sshforwarding.rs Outdated Show resolved Hide resolved
@mdibaiee
Copy link
Member Author

Updated results look like this:

image

TunnelExitNonZero is an error returned by start_serve (because it waits the ssh process), while now there is an error specifically for prepare which returns recognised SSH errors based on its stderr output

@@ -54,15 +54,15 @@ async fn main() -> io::Result<()> {
init_logging(&log_args);

if let Err(err) = run(command).await.as_ref() {
tracing::error!(error = ?err, "network tunnel failed.");
tracing::error!(error = %err, "network tunnel failed.");
Copy link
Member Author

Choose a reason for hiding this comment

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

% signifies the Display implementation of the error, rather than its Debug implementation, so the error looks more human-readable rather than exposing the underlying error struct

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense and is fine for std::io::Result 👍 But a general informational comment:

We use a lot of anyhow::Result which is a really nice crate for chaining errors with contextual information and back traces, and I generally recommend it for all top-level handling of errors.

For anyhow::Result, we always want to use the ?err form when used in a tracing::* message, because that renders the complete error chain in a human-readable fashion. We've previously had situations where we were using the %err form accidentally, which only renders the top-most error context of the chain, and then had to go back and switch to ?err as part of an investigation because the meat of the error was lost.

Copy link
Member

@jgraettinger jgraettinger left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -54,15 +54,15 @@ async fn main() -> io::Result<()> {
init_logging(&log_args);

if let Err(err) = run(command).await.as_ref() {
tracing::error!(error = ?err, "network tunnel failed.");
tracing::error!(error = %err, "network tunnel failed.");
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense and is fine for std::io::Result 👍 But a general informational comment:

We use a lot of anyhow::Result which is a really nice crate for chaining errors with contextual information and back traces, and I generally recommend it for all top-level handling of errors.

For anyhow::Result, we always want to use the ?err form when used in a tracing::* message, because that renders the complete error chain in a human-readable fashion. We've previously had situations where we were using the %err form accidentally, which only renders the top-most error context of the chain, and then had to go back and switch to ?err as part of an investigation because the meat of the error was lost.

@mdibaiee mdibaiee merged commit 7b0a714 into main Oct 25, 2024
1 check passed
@mdibaiee mdibaiee deleted the mahdi/ssh-errors branch October 25, 2024 22:38
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