From 3d2ce7178ea88ee6bcc4b192306cf8c5fc6afc7c Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 12 Sep 2024 01:54:55 +0200 Subject: [PATCH] Main: Improve error reporting when failing to read from files --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 02bd5aa..d391c2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,20 @@ -use handlebars::{Context, Handlebars, Helper, HelperResult, JsonRender, Output, RenderContext, RenderErrorReason}; -use serde_json::{Map, Value}; -use std::{env, error::Error}; +use std::env; use std::fs; + +use anyhow::Result; + +use serde_json::{Map, Value}; use url_escape; -fn main() -> Result<(), Box> { +use handlebars::{Context, Handlebars, Helper, HelperResult, JsonRender, Output, RenderContext, RenderErrorReason}; + +fn main() -> Result<()> { let mut handlebars = Handlebars::new(); let path_to_contents = env::args().nth(1).expect("The first argument to be present."); let output_path = env::args().nth(2).expect("The second argument to be present."); - let contents = fs::read_to_string(path_to_contents).expect("To be able to open a file at the path passed as the first argument."); + let contents = fs::read_to_string(path_to_contents).expect("To be able to read the contents file at the path '{path_to_contents}' passed as the first argument."); let secret_inputs = env::vars().filter(|(key, _)| key.starts_with("SECRET_")); @@ -21,7 +25,8 @@ fn main() -> Result<(), Box> { panic!("Secret environment variable is not in format 'name:path_to_secret'"); }; - let secret_value = fs::read_to_string(path_to_secret)?; + let secret_value = fs::read_to_string(path_to_secret) + .expect("To be able to read in secret '{secret_key}' from path '{path_to_secret}'"); println!("Registering secret '{secret_key}' from '{path_to_secret}'.");