Main: Improve error reporting when failing to read from files
This commit is contained in:
parent
dab8fc1735
commit
3d2ce7178e
1 changed files with 11 additions and 6 deletions
17
src/main.rs
17
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<dyn Error>> {
|
||||
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<dyn Error>> {
|
|||
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}'.");
|
||||
|
||||
|
|
Loading…
Reference in a new issue