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

Wrapped localstorage.setItem in try block to avoid uncaught exceptions. #4826

Merged
merged 1 commit into from May 22, 2014
Merged

Wrapped localstorage.setItem in try block to avoid uncaught exceptions. #4826

merged 1 commit into from May 22, 2014

Conversation

ghost
Copy link

@ghost ghost commented May 22, 2014

Example: QuotaExceededError (iOS simulators)

@yurydelendik
Copy link
Contributor

We were thinking to avoid that (since Promise catches that for us) and handle that in the user of the promise.

@yurydelendik
Copy link
Contributor

At lines 85 and 135, we shall do something like

return this._writeToStorage().then(undefined, function (reason) {
  // unable to write to storage
});

@ghost
Copy link
Author

ghost commented May 22, 2014

Done

try {
localStorage.setItem('database', databaseStr);
} catch (ex) {
reject();
Copy link
Contributor

Choose a reason for hiding this comment

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

it shall do that automatically since it's inside Promise(function () {...})

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you revert back this and the cache above (remove try/catch)?

Copy link
Author

Choose a reason for hiding this comment

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

When I remove the try/catch, the exception is not caught and I still get the error in the console. You think it can be an issue in the Promise implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

We shall investigate that, yes. The following works as expected in FF:

new Promise(function () { throw new Error(); }).then(null, function(e) { console.log('Hi'); }).then(function () { console.log('bye'); })

prints 'hi', 'bye'. We might have a bad polyfill.

Copy link
Contributor

Choose a reason for hiding this comment

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

and Chrome

@yurydelendik
Copy link
Contributor

(just fyi, there is also promise.catch(fn) method but we did not polyfill it yet, which is shortcut promise.then(undefined, fn), see spec -- probably it's now time to add that)

@Snuffleupagus
Copy link
Collaborator

I understand the need to make changes to ViewHistory, given that it's not completely Promise friendly currently.

However, do we really need to change any code in Preferences?
Given that it is written such that it should forward the promises to the caller, couldn't/shouldn't this be handled when calling Preferences.set e.g. like this instead:

Preferences.set('prefName', prefValue).then(function resolved(value) { }, function rejected(reason) { })

@yurydelendik
Copy link
Contributor

Really nice. (Could you also check if native implementation has the 'catch' as well, I think some older implementations might not have it)

Is exception raising in the Promise resolver still a problem in the polyfill version?

@yurydelendik
Copy link
Contributor

I'm thinking having try { ... } catch (e) { this._reject(e); } around https://github.com/mozilla/pdf.js/pull/4826/files#diff-8d2b578d58d4d8c8a2975020fbbc84d9R1183 will fix the issue

@ghost
Copy link
Author

ghost commented May 22, 2014

The exception is indeed still raised. I will look into the Promise polyfill.

@yurydelendik
Copy link
Contributor

@dferer is reverting preferences.js changes be bad in your case? I think we want to keep preferences failing

@ghost
Copy link
Author

ghost commented May 22, 2014

Thanks, it works

@ghost
Copy link
Author

ghost commented May 22, 2014

No I only changed preferences.js because I looked for all occurrences of localstorage,setItem. But I don't have a problem with it. I will revert it (I cannot find any occurrence of Preferences.set though).

Fixed Promise so it rejects on uncaught exception
Catch possible rejection on ViewHistory.setMultiple
@ghost
Copy link
Author

ghost commented May 22, 2014

Done

@yurydelendik
Copy link
Contributor

That's awesome. Thanks.

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/7aff24b1768dd15/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/ecdeba655e8ae7f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/ecdeba655e8ae7f/output.txt

Total script time: 2.90 mins

  • Font tests: FAILED
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://107.22.172.223:8877/ecdeba655e8ae7f/reftest-analyzer.html#web=eq.log

@yurydelendik
Copy link
Contributor

/botio-windows test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/2f4e119eceee480/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/7aff24b1768dd15/output.txt

Total script time: 26.67 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/2f4e119eceee480/output.txt

Total script time: 25.80 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/feb38605d8ef96d/output.txt

yurydelendik added a commit that referenced this pull request May 22, 2014
Wrapped localstorage.setItem in try block to avoid uncaught exceptions.
@yurydelendik yurydelendik merged commit fb74b02 into mozilla:master May 22, 2014
@yurydelendik
Copy link
Contributor

Thank you for the patch

@ghost ghost deleted the localstorage-exceptions branch May 22, 2014 20:29
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.

3 participants