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

Handle the case when a user throws somethign that isnt Error #191

Merged
merged 4 commits into from
Jul 25, 2019

Conversation

dschep
Copy link
Contributor

@dschep dschep commented Jul 11, 2019

No description provided.

@codecov
Copy link

codecov bot commented Jul 11, 2019

Codecov Report

Merging #191 into master will decrease coverage by 0.74%.
The diff coverage is 4.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #191      +/-   ##
==========================================
- Coverage      67%   66.25%   -0.75%     
==========================================
  Files          79       79              
  Lines        1767     1787      +20     
  Branches      422      424       +2     
==========================================
  Hits         1184     1184              
- Misses        455      473      +18     
- Partials      128      130       +2
Impacted Files Coverage Δ
sdk-js/src/lib/transaction.js 39.65% <4.54%> (-3.75%) ⬇️
src/lib/transaction.js 39.65% <0%> (-3.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 907665d...5d5f21d. Read the comment docs.

astuyve
astuyve previously approved these changes Jul 11, 2019
Copy link
Contributor

@astuyve astuyve left a comment

Choose a reason for hiding this comment

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

LGTM!

this.set('error.exception.type', errorStack.exception.type);
this.set('error.exception.message', errorStack.exception.message);
this.set('error.exception.stacktrace', JSON.stringify(errorStack.exception.stacktrace));
if (error instanceof Error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

More a comment - it's not as bulletproof check as it could be:

  • instanceof is configurable in JS since ES2015+ (it can be overriden so it returns true for non error instances)
  • Native errors coming from other realms (e.g. if someone sneaks error from other VM context) will be rejected by instanceof check.

The most solid check I know is: https://github.com/medikoo/type/blob/62c2e32a3568e12d93152d33c7cc882239d57f53/error/is.js#L9-L23

Still, I leave it just as a comment, as cases where above will produce a false positive (or positive false) I assume are highly unlikely in AWS Lambda context

Copy link
Contributor Author

@dschep dschep Jul 15, 2019

Choose a reason for hiding this comment

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

instanceof is configurable in JS since ES2015+ (it can be overriden so it returns true for non error instances)

IMO, if some one goes messing with that, they should know it can break just about anything.

Native errors coming from other realms (e.g. if someone sneaks error from other VM context) will be rejected by instanceof check.

is stackman able to process these native errors too?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, if some one goes messing with that, they should know it can break just about anything.

I agree that we shouldn't take into account cases when someone hacks the environment (by e.g. overriding some native methods or constructors).

But Symbol.hasInstance is a valid ES feature, and imo if something will fail on our side just because someone used it (of course that's extremely unlikely) - it's a bug on our side, no excuses :)

is stackman able to process these native errors too?

As I see it will (they do not seem to do any instanceof checks on input errors)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is stackman able to process these native errors too?

As I see it will (they do not seem to do any instanceof checks on input errors)

That doesn't mean it'll work. It doesn't check for string either, but crashes if you pass it one.

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't mean it'll work

It will, as there's no difference on native error coming from different realm (it's just that it derives from other instance of Error.prototype), otherwise all internal slots (or even V8's specific Error.prepareStackTrace) are same among realms - It's why e.g. Array.isArray(arr) will return true for array coming from any realm but arr instanceof Array will not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah. gotcha 👍

how would you recommend I use the code linked? should I just pull in your library? it seems like a lot to detangle to extract the same functionality.

Copy link
Contributor

Choose a reason for hiding this comment

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

should I just pull in your library?

IMO it'll be a good move, it also has some other valuable type checking goodies, and it's very light (has no deps)

scouredimage
scouredimage previously approved these changes Jul 16, 2019
@dschep dschep dismissed stale reviews from scouredimage and astuyve via 77191f9 July 24, 2019 18:09
@dschep dschep requested review from medikoo and astuyve July 24, 2019 18:11
astuyve
astuyve previously approved these changes Jul 25, 2019
@dschep dschep merged commit 95ca860 into master Jul 25, 2019
@dschep dschep deleted the handle-thrown-non-error branch July 25, 2019 14:22
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

4 participants