Skip to content

Commit

Permalink
Make settings module somewhat crash safe
Browse files Browse the repository at this point in the history
so that #73 doesn't happen again hopefully
  • Loading branch information
yishn committed May 1, 2016
1 parent cc7d012 commit 0880413
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ var defaults = {
context.load = function() {
if (!settingspath) return settings = defaults

settings = JSON.parse(fs.readFileSync(settingspath, { encoding: 'utf8' }))
try {
settings = JSON.parse(fs.readFileSync(settingspath, { encoding: 'utf8' }))
} catch(e) {
settings = {}
}

// Load default settings

Expand Down

2 comments on commit 0880413

@TheIronMarx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than nothing! Did the error message in #73 come from Sabaki or an accompanying library? It would have been nice if that was a bit more verbose and explicit.

@yishn
Copy link
Member Author

@yishn yishn commented on 0880413 May 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what happened is: Your computer crashed when Sabaki was writing data to settings.json, resulting in an incomplete JSON file. Hence the JSON parser couldn't read the file, throwing a syntax error.

Please sign in to comment.