Skip to content

Commit 556bd37

Browse files
committed
fix: Handle empty line in environment file
1 parent e8beb17 commit 556bd37

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/error.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use std::process::{self, ExitCode, Termination};
66

77
use url::Url;
88

9+
use crate::prop;
10+
use crate::prop::ParsePropertyError;
11+
912
pub trait Error: StdError + Termination {}
1013

1114
pub enum FireError {
@@ -17,6 +20,7 @@ pub enum FireError {
1720
GenericIO(String),
1821
TemplateRendering,
1922
TemplateKey(String),
23+
Environment(ParsePropertyError),
2024
Other(String),
2125
}
2226

@@ -37,6 +41,12 @@ impl Display for FireError {
3741
FireError::NoReadPermission(path) => format!("No permission to read file {:?}", path.clone()),
3842
FireError::TemplateRendering => String::from("Unable to render request from template"),
3943
FireError::TemplateKey(key) => format!("Unable to render request due to missing value for key {key}"),
44+
FireError::Environment(err) => match err {
45+
prop::ParsePropertyError::Entry(entry) => format!("Invalid entry in environments file: {entry}"),
46+
prop::ParsePropertyError::Key(key) => format!("Invalid key in environments file: {key}"),
47+
prop::ParsePropertyError::Value(value) => format!("Invalid value in environments file: {value}"),
48+
prop::ParsePropertyError::File(file) => format!("Invalid environments file: {file}"),
49+
},
4050
FireError::Other(err) => format!("Error: {err}"),
4151
};
4252

@@ -55,6 +65,7 @@ impl Termination for FireError {
5565
FireError::GenericIO(_) => ExitCode::from(8),
5666
FireError::TemplateKey(_) => ExitCode::from(9),
5767
FireError::TemplateRendering => ExitCode::from(10),
68+
FireError::Environment(_) => ExitCode::from(11),
5869
FireError::Other(_) => ExitCode::from(1),
5970
}
6071
}

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ fn exec() -> Result<(), FireError> {
6565
};
6666

6767
// Read enviroment variables from system environment and extra environments supplied via cli
68-
let props: Vec<Property> = args.env().expect("Unable to load env vars");
68+
let props: Vec<Property> = match args.env() {
69+
Ok(env) => env,
70+
Err(err) => return Err(FireError::Environment(err)),
71+
};
6972
log::debug!("Received properties {:?}", props);
7073

7174
// Apply template substitution

src/prop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn from_file(path: &Path) -> Result<Vec<Property>, ParsePropertyError> {
7171

7272
content
7373
.lines()
74+
.filter(|line| !line.trim().is_empty())
7475
.map(Property::from_str)
7576
.map(|prop| prop.map(|p| p.with_source(source)))
7677
.collect()

0 commit comments

Comments
 (0)