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

An attempt at handling errors in message passing (perhaps not the best approach) #112

Closed
wants to merge 8 commits into from

Conversation

james-cnz
Copy link

This is my attempt at handling errors between onMessage and sendMessage.
It's perhaps not the best approach, because it duplicates a lot of code, so you might not want to use it as is, but perhaps there's something useful in it to inform a better approach?

Like makeCallback, but checks for returned error-like objects, and converts them back to errors.
Also, in Chrome, chrome.runtime.lastError (at least sometimes) seems not to be an Error, but an error-like object, so this is converted too (just using the same method as for onMessage, although I'm not sure if it's the best approach here).
Like wrapAsyncFunction, but uses makeCallbackForSendMessage
When returning from sendMessage, Firefox seems to convert anything that was thrown into a standard Error, with the message property of the Error getting the message property of what was thrown, if it was an object with a "truthy" message property, or "An unexpected error occurred" otherwise.
I don't think Firefox returns anything else besides the message (i.e. not the type of error, filename, linenumber, etc.).
To allow the same functionality, the message property is returned in an error-like object, to be converted to an Error on arrival.
Added the additional custom methods for sending and receiving messages.
An attempt to revert to original behaviour, to see if it will pass checking.
Attempt to partially restore onMessage change without breaking checks.
@james-cnz
Copy link
Author

There's discussion about this issue in #97 (and this patch might conflict with that patch?)

Also, I wonder if the test that failed after the spacing and comma were fixed might not have really been checking for desired behaviour?

  1. browser-polyfill wrapped runtime.onMessage listener sends the returned value as a message response:
    AssertionError: sendResponse callback has been called with the expected parameters: expected { Object (name, message) } to equal 'fake error 3'
    at thirdResponse.catch.err (test/test-runtime-onMessage.js:193:11)
    at process._tickCallback (internal/process/next_tick.js:109:7)

If I understand this right, if onMessage catches a thrown string, it is expected to call sendResponse with that string? If so, I don't think this is really desired behaviour?

Replaced several instances of:
  typeof [expression] == "object"
with:
  typeof [expression] == "object" && expression
To deal with cases where [expression] is null
@james-cnz
Copy link
Author

This is no longer needed, as it is dealt with in #115.

@james-cnz james-cnz closed this May 15, 2018
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.

None yet

1 participant