Skip to content

Commit

Permalink
correct handling of missing settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudorizer committed Jul 23, 2021
1 parent b6b8b6a commit cef427d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/main/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class RethrownError extends Error {
original_error: Error;
stack_before_rethrow: string;

constructor(message: string, error: Error){
super(message);
this.name = this.constructor.name;
if (!error) throw new Error('RethrownError requires a message and error');
this.original_error = error;
this.stack_before_rethrow = this.stack;
const message_lines = (this.message.match(/\n/g)||[]).length + 1;
this.stack = this.stack.split('\n').slice(0, message_lines+1).join('\n') + '\n' +
error.stack;
}
}
7 changes: 3 additions & 4 deletions src/main/loadSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export async function loadSettings() {
try {
await fsAsync.stat('settings.json');
} catch (e) {
await fsAsync.writeFile(
'settings.json',
JSON.stringify({sessionCookie: '', defaultResolution: {width: 1920, height: 1080}}, null, 2)
);
const err = e as Error;
dialog.showErrorBox('Error', 'Settings.json missing. Be sure to rename settings.json.template to settings.json');
throw new RethrownError(err.message, err);
}

const settingsBuffer = await fsAsync.readFile('settings.json');
Expand Down

0 comments on commit cef427d

Please sign in to comment.