Show errors on failure (#5643)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::commands::configure::handle_configure;
|
||||
use crate::commands::info::handle_info;
|
||||
use crate::commands::project::{handle_project_default, handle_projects_interactive};
|
||||
use crate::commands::recipe::{handle_deeplink, handle_list, handle_open, handle_validate};
|
||||
// Import the new handlers from commands::schedule
|
||||
|
||||
use crate::commands::schedule::{
|
||||
handle_schedule_add, handle_schedule_cron_help, handle_schedule_list, handle_schedule_remove,
|
||||
handle_schedule_run_now, handle_schedule_services_status, handle_schedule_services_stop,
|
||||
|
||||
@@ -2,43 +2,73 @@ use anyhow::Result;
|
||||
use console::style;
|
||||
use goose::config::paths::Paths;
|
||||
use goose::config::Config;
|
||||
use goose::session::session_manager::{DB_NAME, SESSIONS_FOLDER};
|
||||
use serde_yaml;
|
||||
|
||||
fn print_aligned(label: &str, value: &str, width: usize) {
|
||||
println!(" {:<width$} {}", label, value, width = width);
|
||||
}
|
||||
|
||||
use goose::config::base::CONFIG_YAML_NAME;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
fn check_path_status(path: &Path) -> String {
|
||||
if path.exists() {
|
||||
"".to_string()
|
||||
} else {
|
||||
let mut current = path.parent();
|
||||
while let Some(parent) = current {
|
||||
if parent.exists() {
|
||||
return match fs::metadata(parent).map(|m| !m.permissions().readonly()) {
|
||||
Ok(true) => style("missing (can create)").dim().to_string(),
|
||||
Ok(false) => style("missing (read-only parent)").red().to_string(),
|
||||
Err(_) => style("missing (cannot check)").red().to_string(),
|
||||
};
|
||||
}
|
||||
current = parent.parent();
|
||||
}
|
||||
style("missing (no writable parent)").red().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_info(verbose: bool) -> Result<()> {
|
||||
let logs_dir = Paths::in_state_dir("logs");
|
||||
let sessions_dir = Paths::in_data_dir("sessions");
|
||||
let sessions_db = sessions_dir.join("sessions.db");
|
||||
|
||||
// Get paths using a stored reference to the global config
|
||||
let sessions_dir = Paths::in_data_dir(SESSIONS_FOLDER);
|
||||
let sessions_db = sessions_dir.join(DB_NAME);
|
||||
let config = Config::global();
|
||||
let config_dir = Paths::config_dir().display().to_string();
|
||||
let config_dir = Paths::config_dir();
|
||||
let config_yaml_file = config_dir.join(CONFIG_YAML_NAME);
|
||||
|
||||
// Define the labels and their corresponding path values once.
|
||||
let paths = [
|
||||
("Config dir:", config_dir),
|
||||
("Sessions DB (sqlite):", sessions_db.display().to_string()),
|
||||
("Logs dir:", logs_dir.display().to_string()),
|
||||
("Config dir:", &config_dir),
|
||||
("Config yaml:", &config_yaml_file),
|
||||
("Sessions DB (sqlite):", &sessions_db),
|
||||
("Logs dir:", &logs_dir),
|
||||
];
|
||||
|
||||
// Calculate padding: use the max length of the label plus extra space.
|
||||
let basic_padding = paths.iter().map(|(l, _)| l.len()).max().unwrap_or(0) + 4;
|
||||
let label_padding = paths.iter().map(|(l, _)| l.len()).max().unwrap_or(0) + 4;
|
||||
let path_padding = paths
|
||||
.iter()
|
||||
.map(|(_, p)| p.display().to_string().len())
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
+ 4;
|
||||
|
||||
// Print version information
|
||||
println!("{}", style("goose Version:").cyan().bold());
|
||||
print_aligned("Version:", env!("CARGO_PKG_VERSION"), basic_padding);
|
||||
print_aligned("Version:", env!("CARGO_PKG_VERSION"), label_padding);
|
||||
println!();
|
||||
|
||||
// Print location information
|
||||
println!("{}", style("goose Locations:").cyan().bold());
|
||||
println!("{}", style("Paths:").cyan().bold());
|
||||
for (label, path) in &paths {
|
||||
print_aligned(label, path, basic_padding);
|
||||
println!(
|
||||
"{:<label_padding$}{:<path_padding$}{}",
|
||||
label,
|
||||
path.display(),
|
||||
check_path_status(path)
|
||||
);
|
||||
}
|
||||
|
||||
// Print verbose info if requested
|
||||
if verbose {
|
||||
println!("\n{}", style("goose Configuration:").cyan().bold());
|
||||
let values = config.all_values()?;
|
||||
|
||||
@@ -4,7 +4,7 @@ use goose_cli::cli::cli;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
if let Err(e) = goose_cli::logging::setup_logging(None, None) {
|
||||
eprintln!("Warning: Failed to initialize telemetry: {}", e);
|
||||
eprintln!("Warning: Failed to initialize logging: {}", e);
|
||||
}
|
||||
|
||||
let result = cli().await;
|
||||
|
||||
Reference in New Issue
Block a user