mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-24 01:24:28 +01:00
fix: catch errors in configure_provider_dialog and report the error upwards (#860)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use cliclack::spinner;
|
use cliclack::spinner;
|
||||||
use console::style;
|
use console::style;
|
||||||
use goose::agents::{extension::Envs, ExtensionConfig};
|
use goose::agents::{extension::Envs, ExtensionConfig};
|
||||||
use goose::config::{Config, ExtensionEntry, ExtensionManager};
|
use goose::config::{Config, ConfigError, ExtensionEntry, ExtensionManager};
|
||||||
use goose::message::Message;
|
use goose::message::Message;
|
||||||
use goose::providers::{create, providers};
|
use goose::providers::{create, providers};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -24,28 +24,86 @@ pub async fn handle_configure() -> Result<(), Box<dyn Error>> {
|
|||||||
);
|
);
|
||||||
println!();
|
println!();
|
||||||
cliclack::intro(style(" goose-configure ").on_cyan().black())?;
|
cliclack::intro(style(" goose-configure ").on_cyan().black())?;
|
||||||
if configure_provider_dialog().await? {
|
match configure_provider_dialog().await {
|
||||||
println!(
|
Ok(true) => {
|
||||||
"\n {}: Run '{}' again to adjust your config or add extensions",
|
println!(
|
||||||
style("Tip").green().italic(),
|
"\n {}: Run '{}' again to adjust your config or add extensions",
|
||||||
style("goose configure").cyan()
|
style("Tip").green().italic(),
|
||||||
);
|
style("goose configure").cyan()
|
||||||
// Since we are setting up for the first time, we'll also enable the developer system
|
);
|
||||||
ExtensionManager::set(ExtensionEntry {
|
// Since we are setting up for the first time, we'll also enable the developer system
|
||||||
enabled: true,
|
// This operation is best-effort and errors are ignored
|
||||||
config: ExtensionConfig::Builtin {
|
ExtensionManager::set(ExtensionEntry {
|
||||||
name: "developer".to_string(),
|
enabled: true,
|
||||||
},
|
config: ExtensionConfig::Builtin {
|
||||||
})?;
|
name: "developer".to_string(),
|
||||||
} else {
|
},
|
||||||
let _ = config.clear();
|
})?;
|
||||||
println!(
|
}
|
||||||
"\n {}: We did not save your config, inspect your credentials\n and run '{}' again to ensure goose can connect",
|
Ok(false) => {
|
||||||
style("Warning").yellow().italic(),
|
let _ = config.clear();
|
||||||
style("goose configure").cyan()
|
println!(
|
||||||
);
|
"\n {}: We did not save your config, inspect your credentials\n and run '{}' again to ensure goose can connect",
|
||||||
}
|
style("Warning").yellow().italic(),
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let _ = config.clear();
|
||||||
|
|
||||||
|
match e.downcast_ref::<ConfigError>() {
|
||||||
|
Some(ConfigError::NotFound(key)) => {
|
||||||
|
println!(
|
||||||
|
"\n {} Required configuration key '{}' not found \n Please provide this value and run '{}' again",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
key,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(ConfigError::KeyringError(msg)) => {
|
||||||
|
println!(
|
||||||
|
"\n {} Failed to access secure storage (keyring): {} \n Please check your system keychain and run '{}' again. \n If your system is unable to use the keyring, please try setting secret key(s) via environment variables.",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
msg,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(ConfigError::DeserializeError(msg)) => {
|
||||||
|
println!(
|
||||||
|
"\n {} Invalid configuration value: {} \n Please check your input and run '{}' again",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
msg,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(ConfigError::FileError(e)) => {
|
||||||
|
println!(
|
||||||
|
"\n {} Failed to access config file: {} \n Please check file permissions and run '{}' again",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
e,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(ConfigError::DirectoryError(msg)) => {
|
||||||
|
println!(
|
||||||
|
"\n {} Failed to access config directory: {} \n Please check directory permissions and run '{}' again",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
msg,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// handle all other nonspecific errors
|
||||||
|
_ => {
|
||||||
|
println!(
|
||||||
|
"\n {} {} \n We did not save your config, inspect your credentials\n and run '{}' again to ensure goose can connect",
|
||||||
|
style("Error").red().italic(),
|
||||||
|
e,
|
||||||
|
style("goose configure").cyan()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
println!();
|
println!();
|
||||||
@@ -127,7 +185,7 @@ pub async fn configure_provider_dialog() -> Result<bool, Box<dyn Error>> {
|
|||||||
Some(env_value) => {
|
Some(env_value) => {
|
||||||
let _ =
|
let _ =
|
||||||
cliclack::log::info(format!("{} is set via environment variable", key.name));
|
cliclack::log::info(format!("{} is set via environment variable", key.name));
|
||||||
if cliclack::confirm("Would you like to save this value to your config file?")
|
if cliclack::confirm("Would you like to save this value to your keyring?")
|
||||||
.initial_value(true)
|
.initial_value(true)
|
||||||
.interact()?
|
.interact()?
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user