Skip to content

Commit b0a7208

Browse files
author
Jacob Halsey
committed
Config should fail if error, to prevent unexpected changes to distributions.
Various other fixes
1 parent 0521dbf commit b0a7208

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/config.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,27 @@ impl Config {
4343
fs::create_dir_all(&roaming_appdata).unwrap();
4444
let config_path = roaming_appdata.join("config.toml");
4545
if !config_path.exists() {
46-
log::info!("Config file doesn't exist, creating default");
46+
log::warn!("Config file doesn't exist, creating default");
4747
let new = Self::default();
4848
new.save(&config_path);
4949
return new;
5050
}
51-
match fs::read_to_string(config_path) {
52-
Ok(data) => match toml::from_str(&data) {
53-
Ok(config) => return config,
54-
Err(err) => log::error!("Unable to parse config file: {err}"),
55-
},
56-
Err(err) => log::error!("Unable to read config file: {err}"),
51+
let contents = match fs::read_to_string(&config_path) {
52+
Err(e) => panic!(
53+
"Unable to read config file: {}: {}",
54+
config_path.display(),
55+
e
56+
),
57+
Ok(s) => s,
58+
};
59+
match toml::from_str(&contents) {
60+
Err(e) => panic!(
61+
"Unable to parse config file: {}: {}",
62+
config_path.display(),
63+
e
64+
),
65+
Ok(config) => config,
5766
}
58-
log::warn!("Falling back to config defaults");
59-
Self::default()
6067
}
6168

6269
fn save(&self, path: &PathBuf) {

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ unsafe extern "system" fn callback(
7878
_: *const MIB_IPFORWARD_ROW2,
7979
_: MIB_NOTIFICATION_TYPE,
8080
) {
81-
log::info!("NotifyRouteChange called");
8281
let tx = &*(callercontext as *const Sender<RunReason>);
8382
tx.send(RunReason::RouteChange).ok();
8483
}

src/runner.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ pub fn start_runner(config: Config, rx: mpsc::Receiver<RunReason>, tray: TrayHan
3737
debounced += 1;
3838
}
3939
log::info!("Running due to {msg:?} message (and {debounced} debounced messages)");
40-
if let Err(err) = update_dns(&config) {
41-
log::error!("Error running: {err}");
42-
}
43-
if config.show_notifications {
44-
tray.notify_dns_updated();
40+
match update_dns(&config) {
41+
Err(e) => log::error!("Error running: {e}"),
42+
Ok(_) => {
43+
if config.show_notifications {
44+
tray.notify_dns_updated();
45+
}
46+
}
4547
}
4648
});
4749
}
@@ -119,7 +121,7 @@ fn update_distribution(
119121
// https://github.com/microsoft/WSL/issues/6977
120122
distribution.set_read_only(RESOLV_CONF, false).ok();
121123
distribution.write_file(RESOLV_CONF, resolv)?;
122-
distribution.set_read_only(RESOLV_CONF, true).ok();
124+
distribution.set_read_only(RESOLV_CONF, true)?;
123125

124126
// Optionally shutdown the WSL2 distribution once finished
125127
if config.shutdown && distribution.was_stopped() {

0 commit comments

Comments
 (0)