use std::fs;
use rootcause::prelude::*;
fn read_file(path: &str) -> Result<String, Report> {
let content = fs::read_to_string(path)?;
Ok(content)
}
fn load_config(path: &str) -> Result<String, Report> {
let content = read_file(path).context("Failed to load application configuration")?;
Ok(content)
}
fn load_config_with_debug_info(path: &str) -> Result<String, Report> {
let content = load_config(path)
.attach(format!("Config path: {path}"))
.attach("Expected format: TOML")?;
Ok(content)
}
fn startup(config_path: &str, environment: &str) -> Result<(), Report> {
let _config = load_config_with_debug_info(config_path)
.context("Application startup failed")
.attach(format!("Environment: {environment}"))?;
Ok(())
}
fn main() {
if let Err(report) = startup("/nonexistent/config.toml", "production") {
println!("{report}");
println!();
println!("• Lines with ● are contexts (.context()) - what operation failed");
println!("• Lines without ● are attachments (.attach()) - debugging data");
}
}