Skip to content

Commit ea54b56

Browse files
committed
feat(config): display errors when rcfile is invalid
1 parent eae1482 commit ea54b56

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/rcfile.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use {
99
},
1010
log::error,
1111
serde::Deserialize,
12-
std::{collections::HashMap, io, process::Command},
12+
std::{
13+
collections::HashMap,
14+
io,
15+
process::{exit, Command},
16+
},
1317
};
1418

1519
fn empty_custom_types() -> HashMap<String, CustomType> {
@@ -158,7 +162,10 @@ impl Rcfile {
158162
if output.status.success() {
159163
String::from_utf8(output.stdout).map_err(|err| io::Error::new(io::ErrorKind::Other, err))
160164
} else {
161-
Err(io::Error::new(io::ErrorKind::Other, "Failed to run cosmiconfig"))
165+
Err(io::Error::new(
166+
io::ErrorKind::Other,
167+
String::from_utf8(output.stderr).expect("Failed to run cosmiconfig"),
168+
))
162169
}
163170
})
164171
.map(Rcfile::from_json);
@@ -175,7 +182,13 @@ impl Rcfile {
175182

176183
/// Create a new rcfile from a JSON string or revert to defaults
177184
pub fn from_json(json: String) -> Rcfile {
178-
serde_json::from_str(&json).unwrap_or_else(|_| Rcfile::new())
185+
match serde_json::from_str(&json) {
186+
Ok(rcfile) => rcfile,
187+
Err(err) => {
188+
error!("Your syncpack config file failed validation\n {err}");
189+
exit(1);
190+
}
191+
}
179192
}
180193

181194
/// Create every alias defined in the rcfile.

0 commit comments

Comments
 (0)