electron-settings icon indicating copy to clipboard operation
electron-settings copied to clipboard

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

Open linonetwo opened this issue 5 years ago • 4 comments

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 avatar Oct 31 '20 15:10 linonetwo

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

linonetwo avatar Oct 31 '20 15:10 linonetwo

Same issue here

FoonkG avatar Nov 14 '20 15:11 FoonkG

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.

theArina avatar Dec 25 '20 17:12 theArina

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.

WholeMilk avatar Jan 26 '24 23:01 WholeMilk