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

Add try/catch in backend.js when saving a file to guard against local… #283

Merged
merged 4 commits into from
Dec 19, 2018

Conversation

bashlund
Copy link
Contributor

Description of the Change

The browser local storage can get full, then some backend.js calls will fail.
This fix will handle it more gracefully, especially for when compiling contracts.

Benefits

Get error message instead of nothing.

Verification Process

Fill up the local storage with many projects, try to compile a contract. Without the fix it silently fails.

…Storage quota full.

Handle local storage quota full in compiler.js
Copy link
Contributor

@filippsen filippsen left a comment

Choose a reason for hiding this comment

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

[Request]

  • Improved compiler error message. Possible to replicate when there is room to create the build directory or when it is already present, but the bin file cannot be written to. OK

  • Close to the browser's limit, creating a new project and adding files results in multiple "Could not save dappfile" alerts, followed by Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'dapps1.1.0' exceeded the quota.
    The call which causes the problem is localStorage.setItem(DAPP_FORMAT_VERSION, JSON.stringify(data)); in backend.js file.
    The problem is:

QuotaExceededError: Failed to execute 'setItem' on 'Storage': Setting the value of 'dapps1.1.0' exceeded the quota.

New code try and catch in backend.js handles that and possibly other related cases. OK

[Related bug]

  • When compiling under the full storage conditions and without having the build directory in place at all, the compiler hangs forever with the spinning icon. This only happens when there is no room for even creating the build file (directory).
    It appears that setItem (in saveFile) fails to execute due to lack of storage space, resulting in unhandled DOMException. Dozens of (recursive error ? infinite alerts? ) Could not save dappfile. alert messages will also pop up.

[Helpers]

Use the following snippet to fill in the local storage with dummy data:
localStorage.setItem("dummy", new Array((9*512*1024)).join("0"));

Check the current allocation size with:
for(var i in localStorage) console.warn(((localStorage[i].length*2)/1024 / 1024).toFixed(2)+" MB");

[References]

Chromium sets local storage to 10MB.
Link: https://github.com/chromium/chromium/blob/master/content/common/dom_storage/dom_storage_types.h#L24

@bashlund bashlund merged commit a5b77ef into SuperblocksHQ:master Dec 19, 2018
donfrigo pushed a commit to donfrigo/superblocks-lab that referenced this pull request Dec 19, 2018
…Storage quota full. (SuperblocksHQ#283)

Handle local storage quota full in compiler.js
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