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

Prevent BindEvaluator from returning Error objects to web worker #7599

Merged
merged 14 commits into from
Feb 28, 2017

Conversation

kmh287
Copy link
Contributor

@kmh287 kmh287 commented Feb 16, 2017

/to @choumx @jridgewell

I'm not excited about the loss of information here. Any suggestions on how to provide more detailed information?

Fixes #7598

@kmh287 kmh287 requested a review from dreamofabear February 16, 2017 16:12
Copy link

@dreamofabear dreamofabear left a 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

@jridgewell
Copy link
Contributor

As discussed, pass back the stack trace and any other useful information in a new clone-friendly typedef

+100.

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 17, 2017

Looks like stack contains both the message and a stack trace. I think the best approach here would be to simply return that, or just message if stack is unavailable as it isn't standard. If we go with that, then the typedef seems unnecessary to wrap a single string.

Also, bind-impl takes the value in the error mappings returned by the evaluator's functions and calls #createError on them, which can take either Error or string objects.

@jridgewell
Copy link
Contributor

Looks like stack contains both the message and a stack trace

We mutate the error message to mark them as either "dev" or "user". Stack is unchanged by that.

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 17, 2017

I'm sorry I don't follow.

@jridgewell
Copy link
Contributor

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.

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 17, 2017

So you're saying create a user error with just the message and a dev error with the stack?

@jridgewell
Copy link
Contributor

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);

@kmh287
Copy link
Contributor Author

kmh287 commented Feb 17, 2017

I hope I've addressed your concerns, PTAL @choumx @jridgewell

@kmh287 kmh287 mentioned this pull request Feb 21, 2017
@@ -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

Choose a reason for hiding this comment

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

s/vlaues/values

@@ -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.

Choose a reason for hiding this comment

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

* stack: string,
* }}
*/
export let AmpWorkerErrorDef;

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.

Copy link
Contributor Author

@kmh287 kmh287 Feb 21, 2017

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.

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.

@@ -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);

Choose a reason for hiding this comment

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

Nit: s/fullError/error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const parseError = parseErrors[expressionString];
const fullError = new Error(parseError.message);
fullError.stack = parseError.stack;
const err = user().createError(fullError);

Choose a reason for hiding this comment

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

Nit: s/err/userError

Copy link
Contributor Author

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;

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.

const parseError = parseErrors[expressionString];
const error = new Error(parseError.message);
error.stack = parseError.stack;
const userError = user().createError(error);
Copy link
Contributor

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.

errors[expressionString] = new Error(
`Expression "${expressionString} is not cached."`);
const error =
new Error(`Expression "${expressionString}"" is not cached.`);

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}].`);

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);

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.

@dreamofabear
Copy link

@kmh287 You can address those nits in a follow-up. Merging now.

@dreamofabear dreamofabear merged commit 91159e7 into ampproject:master Feb 28, 2017
kmh287 added a commit to kmh287/amphtml that referenced this pull request Feb 28, 2017
adelinamart pushed a commit that referenced this pull request Mar 1, 2017
* 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
kmh287 added a commit that referenced this pull request Mar 1, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
…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
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
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