Skip to content

handle scenario where the JSON data isn't available - #849

Merged
joshaber merged 8 commits into
masterfrom
maybe-json-isnt-there
Jan 30, 2017
Merged

joshaber merged 8 commits into
masterfrom
maybe-json-isnt-there

Conversation

@shiftkey

Copy link
Copy Markdown
Member

As part of implementing #833 I found some clues as to why the integration test might be failing on CI:

2017-01-24T16:45:02.502Z - error: uncaughtException: Unexpected token u in JSON at position 0 date=Tue Jan 24 2017 17:45:02 GMT+0100 (CET), pid=71177, uid=501, gid=20, cwd=/Users/shiftkey/src/desktop, execPath=/Users/shiftkey/src/desktop/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper, version=v6.5.0, argv=[/Users/shiftkey/src/desktop/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper, --type=renderer, --enable-logging, --log-level=0, --no-sandbox, --test-type=webdriver, --primordial-pipe-token=A1B330756C31E8FF0BE5BB3D8F75DD94, --lang=en-GB, --node-integration=true, --background-color=#fff, --hidden-page, --enable-pinch, --num-raster-threads=4, --enable-zero-copy, --disable-partial-raster, --enable-gpu-memory-buffer-compositor-resources, --content-image-texture-target=3553,3553,3553,3553,3553,34037,3553,3553,3553,3553,3553,34037,3553,34037,34037, --video-image-texture-target=3553,3553,3553,3553,3553,34037,3553,3553,3553,3553,3553,34037,3553,34037,34037, --mojo-channel-token=C4B3916404868B600784EAE0DA5B065C, --mojo-application-channel-token=A1B330756C31E8FF0BE5BB3D8F75DD94, --channel=71174.2.702899256], rss=89419776, heapTotal=37785600, heapUsed=23376400, loadavg=[1.8291015625, 1.67529296875, 1.64697265625], uptime=116265
SyntaxError: Unexpected token u in JSON at position 0
at ReadFileContext.Fs.readFile [as callback] (file:///Users/shiftkey/src/desktop/out/renderer.js:7592:34)

at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:365:13)
2017-01-24T16:45:02.505Z - error: An uncaught exception was thrown. If this were a production build it would be reported to Central. Instead, maybe give it a lil lookyloo.

The section in bold maps to this bit of code:

const db: IGemojiDb = JSON.parse(data)

const db: IGemojiDb = JSON.parse(data)

The simplest repro seems to be:

  • on macOS, remove everything in ~/Library/Application Support/GitHub Desktop/ (where Electron stores the local files and caches for Desktop:TNG)
  • npm run build:prod
  • npm run test:integration

Which then gives this test output:

  App
    1) "before each" hook for "opens a window on launch"


  0 passing (1s)
  1 failing

  1) App "before each" hook for "opens a window on launch":
     Error: unknown error: session deleted because of page crash
from tab crashed
      at execute(<Function>, "require") - api.js:57:26

I've also spotted a similar error on Appveyor recently, so hopefully #833 will uncover more of these sorts of issues.

I'm sure there are some flow-on effects from this, but rejecting here is better than suppressing the error...

@shiftkey

Copy link
Copy Markdown
Member Author

Ready for review

@joshaber joshaber self-assigned this Jan 26, 2017
Comment thread app/src/lib/dispatcher/emoji-store.ts Outdated
@@ -87,26 +87,34 @@ export class EmojiStore {
const basePath = process.env.TEST_ENV ? Path.join(__dirname, '..', '..', '..', '..', 'gemoji', 'db') : __dirname

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Fs.readFile(Path.join(basePath, 'emoji.json'), 'utf8', (err, data) => {

const db: IGemojiDb = JSON.parse(data)
const path = Path.join(rootDir, 'emoji.json')

This comment was marked as spam.


if (err) {
reject(err)
return

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

Copy link
Copy Markdown
Member Author

🍎

@shiftkey

Copy link
Copy Markdown
Member Author

Anyway, I'm pretty sure the root cause of this issue:

  • Path to a non-existent file passed into readFile
  • In the callback, err is set and data is undefined
  • No error handling, which would have caught this
  • internally JSON.parse tries to understand what data is, stringifies it into 'undefined'
  • 💥

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🦆

}

public read(): Promise<void> {
public read(rootDir: string): Promise<void> {

This comment was marked as spam.


if (err) {
reject(err)
return

This comment was marked as spam.

Comment thread app/src/lib/dispatcher/app-store.ts Outdated
})

this.emojiStore.read().then(() => this.emitUpdate())
const rootDir = remote.app.getAppPath()

This comment was marked as spam.

@shiftkey

Copy link
Copy Markdown
Member Author

🐶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants