nathanbuchar / electron-settings

📝 A simple persistent user settings framework for Electron.
https://electron-settings.js.org
MIT License
814 stars 60 forks source link

electron-settings/package.json: Unexpected end of JSON input #138

Open linonetwo opened 3 years ago

linonetwo commented 3 years ago

SyntaxError: Error parsing /Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/dist/mac/TiddlyGit.app/Contents/Resources/app.asar/node_modules/electron-settings/package.json: Unexpected end of JSON input

Uncaught Exception:
SyntaxError: Error parsing /Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/dist/mac/TiddlyGit.app/Contents/Resources/app.asar/node_modules/electron-settings/package.json: Unexpected end of JSON input
    at parse (<anonymous>)
    at readPackage (internal/modules/cjs/loader.js:261:20)
    at resolveExports (internal/modules/cjs/loader.js:436:15)
    at Function.Module._findPath (internal/modules/cjs/loader.js:479:31)
    at Module._resolveFilename (internal/modules/cjs/loader.js:874:27)
    at Function.n._resolveFilename (electron/js2c/browser_init.js:257:1128)
    at Module._load (internal/modules/cjs/loader.js:732:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12745)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/dist/mac/TiddlyGit.app/Contents/Resources/app.asar/build/electron.js:6:18)
    at Module._compile (internal/modules/cjs/loader.js:1078:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12745)
linonetwo commented 3 years ago

This is similar to https://github.com/desktop/dugite/issues/414

FoonkG commented 3 years ago

Same issue here

theArina commented 3 years ago

Not the same case, but i get SyntaxError: Unexpected end of JSON input when the settings file is empty. It's not exactly an issue, cause json files shouldn't be empty, but i would suggest to the developer adding emptiness check just in case.

WholeMilk commented 8 months ago

I also ran into this issue, after digging into it a bit, this is partially due to how the set()/setSync() are designed. Both of these "write" functions loads existing settings from disk first and perform a partial update by path with the new data, because of this, when the settings data file on disk has invalid JSON format, the loading/parsing fails and thus fails the write function call. I can think of two things to help solve this:

  1. Better documentation on the set/partial-update functions, make it clear when using those functions, the settings file cannot be invalid JSON structure. I think many users that do not care about partial write are surprised that a seemingly write action is dependent on preexisting data being valid.
  2. Expose/export saveSettings()/saveSettingsSync() as a simpler pure/no-side-effect write counter part of set()/setSync() regardless of preexisting data and contrast their usage differences in doc.