Skip to content

Commit cf051a9

Browse files
committed
Resolver-related code cleanup
This commit introduces a new exit code (4) for when no system resolver can be found, instead of just crashing. It also introduces ResolverType, which is similar to code that used to be present. While the previous code passed all its unit tests, there was system-level code (obtaining the resolvers) being called from those unit tests, which isn't something unit tests are meant to be doing — there's no guarantee that they'll continue to work on systems with different network conifgurations. Because ResolverType is just a type, it can be used in tests. (Resolver has had its PartialEq impl stripped, and there's now a warning, to stop this from happening again.) The refactor lets us remove some Clippy allowances, which is always nice.
1 parent d7b1da9 commit cf051a9

File tree

5 files changed

+179
-127
lines changed

5 files changed

+179
-127
lines changed

man/dog.1.md

+3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ EXIT STATUSES
232232
3
233233
: If there was a problem with the command-line arguments.
234234

235+
4
236+
: If there was a problem obtaining the system nameserver information.
237+
235238

236239
AUTHOR
237240
======

src/main.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#![allow(clippy::module_name_repetitions)]
1717
#![allow(clippy::option_if_let_else)]
1818
#![allow(clippy::too_many_lines)]
19-
#![allow(clippy::unit_arg)]
20-
#![allow(clippy::unused_self)]
2119
#![allow(clippy::upper_case_acronyms)]
22-
#![allow(clippy::useless_let_if_seq)]
2320
#![allow(clippy::wildcard_imports)]
2421

2522
#![deny(unsafe_code)]
@@ -109,7 +106,16 @@ fn run(Options { requests, format, measure_time }: Options) -> i32 {
109106
let timer = if measure_time { Some(Instant::now()) } else { None };
110107

111108
let mut errored = false;
112-
for (request_list, transport) in requests.generate() {
109+
110+
let request_tuples = match requests.generate() {
111+
Ok(rt) => rt,
112+
Err(e) => {
113+
eprintln!("Unable to obtain resolver: {}", e);
114+
return exits::SYSTEM_ERROR;
115+
}
116+
};
117+
118+
for (request_list, transport) in request_tuples {
113119
let request_list_len = request_list.len();
114120
for (i, request) in request_list.into_iter().enumerate() {
115121
let result = transport.send(&request);
@@ -189,4 +195,7 @@ mod exits {
189195

190196
/// Exit code for when the command-line options are invalid.
191197
pub const OPTIONS_ERROR: i32 = 3;
198+
199+
/// Exit code for when the system network configuration could not be determined.
200+
pub const SYSTEM_ERROR: i32 = 4;
192201
}

0 commit comments

Comments
 (0)