Skip to content

Error parsing JSON, possible attempt to deserialize HTML #1505

Closed

Description

@niik

Looks to me like we're attempting to parse HTML as JSON somewhere in the app.

version: 0.5.3
osVersion: Windows 6.1.7601
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
at file:///app/renderer.js:3:77588
at XMLHttpRequest.J.ae.onreadystatechange (file:///app/renderer.js:3:74786)

Activity

  1. added
    bug
    on May 16, 2017
  2. added this to the M5: Post-Beta Bougie milestone on May 16, 2017
  3. shiftkey commented on May 17, 2017

    @shiftkey
    Member

    Disassembling the release app suggests it's the usage inside Octokat.js: https://github.com/philschatz/octokat.js/blob/master/src/requester.js#L177

    Without more context, the 500ing of /user/public_emails is probably my best guess of the root cause, which is #1508.

    @niik any objections to closing this as a dupe of #1508?

  4. added
    investigation-needed
    on May 17, 2017
  5. shiftkey commented on May 18, 2017

    @shiftkey
    Member

    Closing this out as a dupe of #1508.

    Reopen if we find another API call that fails in this way that tries to parse HTML as JSON.

  6. joshaber commented on May 18, 2017

    @joshaber
    Contributor

    We're seeing some other variations on this as well:

    SyntaxError: Unexpected token � in JSON at position 0
        at JSON.parse (<anonymous>)
    at file:///app/renderer.js:3:77567
    at XMLHttpRequest.J.ae.onreadystatechange (file:///app/renderer.js:3:74765)
    
    SyntaxError: Unexpected token : in JSON at position 0
        at JSON.parse (<anonymous>)
    at file:///app/renderer.js:3:77567
    at XMLHttpRequest.J.ae.onreadystatechange (file:///app/renderer.js:3:74765)
    
  7. self-assigned this
    on May 18, 2017
  8. shiftkey commented on May 25, 2017

    @shiftkey
    Member

    Went back to this one this morning and found myself staring at this snippet again in the octokat.js requester:

    if (jqXHR.responseText && ajaxConfig.dataType === 'json') {
        data = JSON.parse(jqXHR.responseText)
    } else {
        data = jqXHR.responseText
    }

    And then I realised there's a subtle error in here. ajaxConfig.dataType is set by octokat.js as part of what it thinks is the expected response, but for non-JSON results this value isn't going to reflect reality. I thought jqXHR.dataType would reflect reality but that's also set by the library.

    The Correct Way™ would be for the callback to look at the response header, and that seems fine as per the dev tools:

    > jqXHR.getResponseHeader('Content-Type')
    "application/json; charset=utf-8"
    

    I'd put together a patch for this but it looks like an update for octokat.js is imminent which has rewritten the requester code to this:

    // Convert to JSON if we are expecting JSON
    // TODO: use a blob if we are expecting a binary
    if (!options.isRaw) {
      dataPromise = response.json()
    } else {
      dataPromise = response.text()
    }

    This seems a bit more resilient, but I'm not 100% confident on that given how it still relies on options rather than poking at the response, so I'm testing this as a scoped package and poking around to see if there's anything else I can provide upstream.

  9. shiftkey commented on May 25, 2017

    @shiftkey
    Member

    I'm experimenting with a scoped package based on the upcoming 0.9.0 release of Octokat.js and philschatz/octokat.js#172 which should improve this situation:

    The additional changes coming with 0.9.0 make me think we should do a bit more testing but let me know your feels on this @desktop/core if you think we should get this into an update sooner.

  10. joshaber commented on May 25, 2017

    @joshaber
    Contributor

    I'm fine with updating to 0.9.x once your PR lands to get this fixed. It's one of our most common haystack reports, but we don't have users banging down the door about it 🤷‍♂️

  11. locked as resolved and limited conversation to collaborators on Jul 22, 2018
  12. unlocked this conversation on Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buginvestigation-needed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions