sindresorhus/electron-store

Add error hook option

Open

#86 opened on Sep 25, 2019

View on GitHub
 (6 comments) (0 reactions) (0 assignees)JavaScript (4,304 stars) (150 forks)batch import
enhancementhelp wanted

Description

I was playing with migrations and noticed some weird behavior. So to be able to run specific migrations I modified the store file by hand. No matter what I did, I always ended up completely empty store data. In the end, revealed that my JSON file was slightly invalid (because of my modifications), e.g.:

{"foo":"bar",}

notice the extra ,

This causes the fact that when I create the store instance, the data parsing fails and store data is empty. As a side effect, I lose all my data in the json file.

I know editing these files by hand is something people should not really do, but just silently ignoring the parsing error and emptying the file is just super bad IMHO.

IMO better to fail the instantiation if the file is not parseable and not to wipe all the data.

Contributor guide