Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to get object from local datastore #773

Closed
joshuamshana opened this issue Mar 30, 2019 · 2 comments · Fixed by #803
Closed

Failed to get object from local datastore #773

joshuamshana opened this issue Mar 30, 2019 · 2 comments · Fixed by #803

Comments

@joshuamshana
Copy link

Issue Description

When try to get pinned object from local datastore, results in JSON.parse error

Steps to reproduce

  1. Pin object to local datastore
  2. Query object from local datastore

Expected Results

Expected list of object from local datastore

Actual Outcome

SyntaxError: Unexpected token b in JSON at position 0
at JSON.parse ()
at Object.getAllContents (LocalDatastoreController.browser.js:59)
at Object._getAllContents (LocalDatastore.js:61)
at Object. (LocalDatastore.js:313)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:4200/anonymous function) [as next]

Environment Setup

  • Server

    • parse-server version: 3.1.3
    • Operating System: Ubuntu Desktop 18.04
    • Localhost or remote server? localhost
  • JS SDK

    • JS SDK version: 2.2.1
    • Application? : Browser

Logs/Trace

SyntaxError: Unexpected token b in JSON at position 0
at JSON.parse ()
at Object.getAllContents (LocalDatastoreController.browser.js:59)
at Object._getAllContents (LocalDatastore.js:61)
at Object. (LocalDatastore.js:313)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:4200/anonymous function) [as next] (http://localhost:4200/vendor.js:142466:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at asyncToGenerator.js:32

@joshuamshana
Copy link
Author

I found out in localstorage of browser there is an installationId which is not JSON object.
So i edit LocalDatastoreController( js file of parse sdk from nodemodule ) : getAllContents (LocalDatastoreController.browser.js:59). i rewrite LDS[key] = JSON.parse(value); with try { LDS[key] = JSON.parse(value); } catch (e) { console.warn('Parse localdatastore warn: key==>' + key+ ', value==>'+ value+ ', error ==>'+ e ) }. to ignore installationId of the device

@dplewis
Copy link
Member

dplewis commented Apr 18, 2019

@fahamutech I can submit a PR. Can you post the exact payload that threw the error.

dplewis added a commit that referenced this issue Apr 24, 2019
Fixes: #773

Should we log key, values?

Console.log vs warn vs error?
dplewis added a commit that referenced this issue Apr 24, 2019
* LDS: Improve Error Handling

Fixes: #773

Should we log key, values?

Console.log vs warn vs error?

* test fix

* test debug

* test mock localstorage

* final test before I give up

* remove mock

* cleanup
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 a pull request may close this issue.

2 participants