Skip to content

Commit fb84831

Browse files
committed
fix: panic if default config also doesn't exist
1 parent ab7efbf commit fb84831

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn deserialize(content: &str) -> Result<Config, DigsError> {
2828
}
2929

3030
pub fn get(path: &Path) -> Result<Config, DigsError> {
31-
// path must be exists. unwrap is safe here.
32-
let file_content = fs::read_to_string(path).unwrap();
31+
let file_content = fs::read_to_string(path)?;
3332
deserialize(&file_content)
3433
}

src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ pub enum DigsError {
2626
// All cases from trust-dns
2727
#[error("Error: {0:?}")]
2828
ForeignError(#[from] ClientError),
29+
30+
// All cases of `std::io::Error`.
31+
#[error(transparent)]
32+
IOError(#[from] std::io::Error),
2933
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn run() -> Result<()> {
2424
// get config file
2525
let config_path: PathBuf = match matches.value_of("config") {
2626
Some(path) => utils::is_exist(path)?,
27-
None => "digs.toml".into(),
27+
None => utils::is_exist("digs.toml".into())?,
2828
};
2929
let config = config::get(&config_path)?;
3030

tests/integration_test.rs

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ fn help() {
1111
.stdout(predicate::str::contains("digs \u{25cf} dig many at once"));
1212
}
1313

14+
#[test]
15+
fn default_config_not_found() {
16+
let mut cmd = Command::cargo_bin("digs").unwrap();
17+
cmd.arg("example.net").arg("-f").arg("file/doesnt/exist");
18+
cmd.assert()
19+
.failure()
20+
.stderr(predicate::str::contains("No such file"));
21+
}
22+
1423
#[test]
1524
fn config_not_found() {
1625
let mut cmd = Command::cargo_bin("digs").unwrap();

0 commit comments

Comments
 (0)