Merge branch 'better-error' into 'main'
Validate client configuration before running commands See merge request kernald/immich-tools!8
This commit is contained in:
commit
bcae3b3cb9
1 changed files with 22 additions and 1 deletions
23
src/main.rs
23
src/main.rs
|
@ -3,7 +3,8 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
|
||||||
use crate::args::Commands;
|
use crate::args::Commands;
|
||||||
use args::{PeopleCommands, ServerCommands};
|
use args::{PeopleCommands, ServerCommands};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
|
use color_eyre::Section;
|
||||||
use commands::missing_date_of_birth::missing_date_of_birth;
|
use commands::missing_date_of_birth::missing_date_of_birth;
|
||||||
use commands::server_version::server_version;
|
use commands::server_version::server_version;
|
||||||
use commands::sync_date_of_birth::sync_date_of_birth;
|
use commands::sync_date_of_birth::sync_date_of_birth;
|
||||||
|
@ -46,6 +47,8 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let client = get_client(&conf.server_url, &conf.api_key)?;
|
let client = get_client(&conf.server_url, &conf.api_key)?;
|
||||||
|
|
||||||
|
validate_client_connection(&client).await?;
|
||||||
|
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Commands::People { people_command } => match people_command {
|
Commands::People { people_command } => match people_command {
|
||||||
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
||||||
|
@ -79,3 +82,21 @@ fn get_client(url: &str, api_key: &str) -> Result<Client> {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn validate_client_connection(client: &Client) -> Result<()> {
|
||||||
|
client
|
||||||
|
.validate_access_token()
|
||||||
|
.await
|
||||||
|
.wrap_err_with(|| "Unable to connect to Immich")
|
||||||
|
.with_suggestion(|| "The API key might be invalid")
|
||||||
|
.with_suggestion(|| "There server URL might be invalid, it should likely end in /api")
|
||||||
|
.with_note(|| format!("The provided server URL was {}", client.baseurl()))
|
||||||
|
.with_note(|| {
|
||||||
|
format!(
|
||||||
|
"The API version for this client is {}, make sure the server version is compatible",
|
||||||
|
client.api_version()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue