From 0bfd6344a5fd6f5581cb7bdd142cd7c5ae93a7f2 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Thu, 6 Nov 2025 11:17:06 +0000 Subject: [PATCH 1/2] Add logging to client configuration discovery Include info about where config is coming from (file, CLI, defaults). --- src/client/config.rs | 18 ++++++++++++++++++ src/client/mod.rs | 16 ++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/client/config.rs b/src/client/config.rs index 3369b263..da7d8ab0 100644 --- a/src/client/config.rs +++ b/src/client/config.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::io::ErrorKind; use std::path::Path; @@ -60,3 +61,20 @@ impl ClientConfiguration { self } } + +impl Display for ClientConfiguration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "ClientConfiguration(host: ")?; + match self.host { + Some(ref h) => write!(f, "{h}")?, + None => write!(f, "None")?, + } + write!(f, ", auth: ")?; + match self.auth { + Some(ref a) => write!(f, "{a}")?, + None => write!(f, "None")?, + } + write!(f, ")")?; + Ok(()) + } +} diff --git a/src/client/mod.rs b/src/client/mod.rs index f32a40c4..c85179ce 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -5,6 +5,7 @@ use graphql_client::{GraphQLQuery, Response}; use reqwest::Client; use serde::de::DeserializeOwned; use serde::Serialize; +use tracing::info; use url::Url; use crate::cli::client::{ClientCommand, ClientOptions, ConfigurationOptions}; @@ -25,13 +26,18 @@ pub async fn run_client(options: ClientOptions) { } = options; let conf = match ClientConfiguration::from_default_file().await { - Ok(conf) => conf.with_host(connection.host).with_auth(connection.auth), + Ok(conf) => { + info!("Configuration from file: {conf}"); + conf.with_host(connection.host).with_auth(connection.auth) + } Err(e) => { println!("Could not read configuration: {e}"); return; } }; + info!("Configuration with CLI args included: {conf}"); + let client = match NumtrackerClient::from_config(conf).await { Ok(client) => client, Err(e) => { @@ -86,14 +92,16 @@ struct ConfigureMutation; impl NumtrackerClient { async fn from_config(config: ClientConfiguration) -> Result { - let host = config - .host - .unwrap_or(Url::parse("http://localhost:8000").expect("Constant URL is valid")); + let host = config.host.unwrap_or_else(|| { + info!("No host specified, defaulting to localhost:8000"); + Url::parse("http://localhost:8000").expect("Constant URL is valid") + }); let auth = match config.auth { Some(auth) => Some(cli_auth::get_access_token(&auth).await?), None => None, }; + info!("Querying {host} with auth: {auth:?}"); Ok(NumtrackerClient { auth, host }) } From 7243f88b4c1b8f2f358276984ce5a27f50c68dc5 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Fri, 28 Nov 2025 15:21:13 +0000 Subject: [PATCH 2/2] Improve error messages in client Check for 'successful' http requests that return 4xx statuses. Print a message if a response has neither data nor errors. --- src/client/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index c85179ce..1355d5c1 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -118,7 +118,13 @@ impl NumtrackerClient { None => client, Some(token) => client.bearer_auth(token), }; - client.json(&content).send().await?.json().await + client + .json(&content) + .send() + .await? + .error_for_status()? + .json() + .await } async fn query_configuration(self, instrument: Option>) -> Result<(), ClientError> { @@ -144,6 +150,8 @@ impl NumtrackerClient { conf.tracker_file_extension.unwrap_or(conf.instrument) ); } + } else if data.errors.is_none() { + println!("Query returned no data or errors"); } Ok(()) }