Skip to content

Commit

Permalink
clean up errors, print Display instead of Debug format of error
Browse files Browse the repository at this point in the history
  • Loading branch information
mdibaiee committed Oct 25, 2024
1 parent a9184c3 commit 20b6d9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
24 changes: 5 additions & 19 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
use base64::DecodeError;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("io operation error.")]
IoError(#[from] std::io::Error),

#[error("Json serialization error.")]
JsonError(#[from] serde_json::Error),

#[error("Failed to decode base64 content of OpenSSH key.")]
DecodeError(#[from] DecodeError),
#[error("{0}")]
IO(#[from] std::io::Error),

#[error("SSH forwarding network tunnel exit with non-zero exit code {0}")]
TunnelExitNonZero(String),

#[error("network tunnel requested, but no destination address was found in the endpoint configuration")]
MissingDestinationAddress,

#[error("malformed destination address {0}")]
BadDestinationAddress(String),

// Used to silently terminate the SSH tunnel without logging any further errors
// Used to bubble up SSH tunnel errors without logging any further errors
// this allows the last `ssh: ` log to be reported as the main error to the user
#[error("")]
SilentError
#[error("{0}")]
SSH(String)
}
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ async fn main() -> io::Result<()> {
init_logging(&log_args);

if let Err(err) = run(command).await.as_ref() {
if !matches!(err, Error::SilentError) {
tracing::error!(error = ?err, "network tunnel failed.");
}
tracing::error!(error = %err, "network tunnel failed.");
std::process::exit(1);
}
Ok(())
Expand Down
12 changes: 4 additions & 8 deletions src/sshforwarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,13 @@ impl NetworkTunnel for SshForwarding {
} else if line.starts_with("Warning: Permanently added") {
tracing::debug!("{}", &line);
} else if line.contains("Permission denied") {
tracing::error!("{}", &line);
return Err(Error::SilentError)
return Err(Error::SSH(line));
} else if line.contains("Network is unreachable") {
tracing::error!("{}", &line);
return Err(Error::SilentError)
return Err(Error::SSH(line));
} else if line.contains("Connection timed out") {
tracing::error!("{}", &line);
return Err(Error::SilentError)
return Err(Error::SSH(line));
} else if line.contains("Operation timed out") {
tracing::error!("n{}", &line);
return Err(Error::SilentError)
return Err(Error::SSH(line));
} else {
tracing::info!("ssh: {}", &line);
}
Expand Down

0 comments on commit 20b6d9a

Please sign in to comment.