fix: catch write errors for settings

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2023-11-08 12:47:48 +01:00
parent 3643ecf7d6
commit 64fd1eee68
No known key found for this signature in database
GPG key ID: E13DFD4B47127951

View file

@ -30,7 +30,11 @@ function createSettingsStore<T extends object = any>(file: string, settings: T)
const store = new SettingsStore(settings);
store.addGlobalChangeListener(o => {
mkdirSync(dirname(file), { recursive: true });
try {
writeFileSync(file, JSON.stringify(o, null, 4));
} catch (err) {
console.error(`Failed to save ${file}`, err);
}
});
return store;