Skip to content

Commit

Permalink
Improve connection error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmunns committed Jan 21, 2025
1 parent 7090b03 commit f2d3a7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tools/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/poststation-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "poststation-cli"
# This version of the CLI tested with poststation v0.14.0
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["James Munns <[email protected]>"]
description = "A CLI tool for poststation"
Expand Down
26 changes: 22 additions & 4 deletions tools/poststation-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use device::{device_cmds, Device};
use directories::ProjectDirs;
use postcard_rpc::host_client::{EndpointReport, TopicReport};
use poststation_sdk::{
connect, connect_insecure, schema::schema::owned::OwnedDataModelType, PoststationClient,
connect, connect_insecure, schema::schema::owned::OwnedDataModelType, ConnectError,
PoststationClient,
};

mod device;
Expand Down Expand Up @@ -62,12 +63,29 @@ async fn inner_main(cli: Cli) -> anyhow::Result<()> {
.unwrap_or_else(|| "127.0.0.1:51837".parse().unwrap());

let command = cli.command;
let client = if cli.insecure {
let client_res = if cli.insecure {
connect_insecure(server.port()).await
} else {
connect(server).await
}
.unwrap();
};

let client = match client_res {
Ok(c) => c,
Err(e) => match e {
ConnectError::CaCertificate => {
bail!("An error with the CA certificate occurred. Ensure you have the correct path and certificate for the server you want to connect to.");
}
ConnectError::Connection => {
bail!("An error occurred while establishing a a connection. Ensure the server is running, and your CLI and server settings match.");
}
ConnectError::Protocol => {
bail!("A protocol error occurred. Ensure that your CLI and Server are compatible versions");
}
other => {
bail!("An unknown error occurred: {other:?}");
}
},
};

match command {
Commands::Ls => {
Expand Down

0 comments on commit f2d3a7d

Please sign in to comment.