-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Prevent BindEvaluator from returning Error objects to web worker #7599
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bind-impl.js
also needs to be changed- As discussed, pass back the stack trace and any other useful information in a new clone-friendly typedef
+100. |
Looks like Also, bind-impl takes the value in the error mappings returned by the evaluator's functions and calls |
We mutate the error message to mark them as either "dev" or "user". Stack is unchanged by that. |
I'm sorry I don't follow. |
We need both if we want to reconstruct an Error and treat it normally (marking it user error so we don't receive it in the logs) on AMP doc side. |
So you're saying create a user error with just the message and a dev error with the stack? |
We can reconstruct on our side: const { message, stack } = receivedMessage;
const error = new Error(message);
error.stack = stack;
// Treat it however
throw error;
user().error(error); |
219d820
to
edd9e8b
Compare
I hope I've addressed your concerns, PTAL @choumx @jridgewell |
src/web-worker/web-worker.js
Outdated
@@ -60,5 +60,7 @@ self.addEventListener('message', function(event) { | |||
|
|||
/** @type {FromWorkerMessageDef} */ | |||
const message = {method, returnValue, id}; | |||
// `message` may only contain vlaues or objects handled by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/vlaues/values
src/web-worker/web-worker.js
Outdated
@@ -60,5 +60,7 @@ self.addEventListener('message', function(event) { | |||
|
|||
/** @type {FromWorkerMessageDef} */ | |||
const message = {method, returnValue, id}; | |||
// `message` may only contain vlaues or objects handled by the | |||
// structured clone algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/web-worker/amp-worker.js
Outdated
* stack: string, | ||
* }} | ||
*/ | ||
export let AmpWorkerErrorDef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this typedef shouldn't live here since:
- It's not actually used by any code in this file and
- It adds an unnatural dependency to
bind-evaluator
(the worker's use of bind-evaluator is an implementation detail, not vice-versa)
Move this to bind-evaluator
since this only concerns the boundary between that class and bind-impl
. Also, I think the helper methods below are simple enough to be unnecessary and not worthwhile as a layer of indirection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this create a dependency on bind-evaluator?
Also, what happens if/when more functionality depends on the worker. This prevents everyone who uses the worker from rolling their own error type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this create a dependency on bind-evaluator?
I meant bind-evaluator
shouldn't depend on amp-worker
.
Also, what happens if/when more functionality depends on the worker. This prevents everyone who uses the worker from rolling their own error type.
I'm not so sure that future use cases will need to return Error
objects. bind-impl
's usage of reportError
is pretty particular.
479861a
to
2827588
Compare
extensions/amp-bind/0.1/bind-impl.js
Outdated
@@ -197,7 +197,10 @@ export class Bind { | |||
Object.keys(parseErrors).forEach(expressionString => { | |||
const elements = this.expressionToElements_[expressionString]; | |||
if (elements.length > 0) { | |||
const err = user().createError(parseErrors[expressionString]); | |||
const parseError = parseErrors[expressionString]; | |||
const fullError = new Error(parseError.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/fullError/error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
extensions/amp-bind/0.1/bind-impl.js
Outdated
const parseError = parseErrors[expressionString]; | ||
const fullError = new Error(parseError.message); | ||
fullError.stack = parseError.stack; | ||
const err = user().createError(fullError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/err/userError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* stack: string, | ||
* }} | ||
*/ | ||
export let EvaluatorErrorDef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
extensions/amp-bind/0.1/bind-impl.js
Outdated
const parseError = parseErrors[expressionString]; | ||
const error = new Error(parseError.message); | ||
error.stack = parseError.stack; | ||
const userError = user().createError(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You can pass parseError.message
directly into #createError
, and set #stack
on the returned error.
6b6c2cd
to
6e5af94
Compare
errors[expressionString] = new Error( | ||
`Expression "${expressionString} is not cached."`); | ||
const error = | ||
new Error(`Expression "${expressionString}"" is not cached.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2 spaces
errors[expressionString] = new Error( | ||
`"${result}" is not a valid result for [${property}].`); | ||
const error = | ||
new Error(`"${result}" is not a valid result for [${property}].`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2 spaces
const elements = this.expressionToElements_[expressionString]; | ||
if (elements.length > 0) { | ||
const evalError = errors[expressionString]; | ||
const err = user().createError(evalError.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: userError
to be consistent with above.
@kmh287 You can address those nits in a follow-up. Merging now. |
* Prevent BindEvaluator from returning error objects to web worker * cleanup * pr comments * cleanup * cleanup * lint error * added tests and addressed error from CI * pr comments * pr comments * pr comments
…project#7599) * Prevent BindEvaluator from returning error objects to web worker * cleanup * pr comments * cleanup * cleanup * lint error * added tests and addressed error from CI * pr comments * pr comments * pr comments
/to @choumx @jridgewell
I'm not excited about the loss of information here. Any suggestions on how to provide more detailed information?
Fixes #7598