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

Fix SDK crash when Error.prepareStackTrace returns a non-string #254

Merged
merged 7 commits into from
May 25, 2017

Conversation

OsvaldoRosado
Copy link
Member

This turns off Zone stack-rewriting which can't handle non-default stack trace formats. This resolves an incompatibility with "caller", which when used in conjunction with this SDK would crash upon use.

orig['prepareStackTrace'] = (e, s) => {
// Remove some AI and Zone methods from the stack trace
// Otherwise we leave side-effects
s.splice(0, 3);

Choose a reason for hiding this comment

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

Does s always have three methods? Is it possible that we are removing too much?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't expect the first 3 methods to change without a code change on our side, since they're all basically passing around our error handlers and zone error handlers. (In other words, the whole top of the stack is just AI SDK and Zone) If we ever change how our error handling works we'll have to adjust this number.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a UT to check if this number is correct

@@ -168,7 +168,25 @@ export class CorrelationContextManager {
return AppInsightsAsyncCorrelatedErrorWrapper.apply(Object.create(AppInsightsAsyncCorrelatedErrorWrapper.prototype), arguments);
}

// Is this object set to rewrite the stack?
// If so, we should turn off some Zone stuff that is prone to break
var stackRewrite = orig['stackRewrite'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Make "strackRewrite" and "prepare" constants?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that might be confusing for this use case. Perhaps I should use dot notation instead and cast to any. The only reason I'm using this bracket notation is to avoid typescript errors on these hidden properties and methods

orig['prepareStackTrace'] = (e, s) => {
// Remove some AI and Zone methods from the stack trace
// Otherwise we leave side-effects
s.splice(0, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is 3? Trying to see how hard it will be for someone unfamiliar with zone to support this later

Copy link
Member Author

@OsvaldoRosado OsvaldoRosado May 19, 2017

Choose a reason for hiding this comment

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

3 here is the number of methods we add to the stack trace. The library that we crash on will still fail (though not crash!) if we don't remove ourselves from the trace

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a UT to check if this number is correct. If we ever add more methods that make this magic number incorrect, the UT will fail, making it obvious this needs to change.

orig.apply(this, arguments);

// Restore Zone stack rewriting settings
orig['stackRewrite'] = stackRewrite;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to wrap it into try...finally to restore orig always?

Copy link
Member Author

@OsvaldoRosado OsvaldoRosado May 19, 2017

Choose a reason for hiding this comment

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

Good idea! I'm not sure how the program can really proceed if apply fails however, since it cannot at that point construct the error object. Apply failing is what caused the original crash as well. Any ideas on what object to return if we do get an exception?

@OsvaldoRosado OsvaldoRosado merged commit aec281b into develop May 25, 2017
@OsvaldoRosado OsvaldoRosado added this to the 0.20.1 milestone May 25, 2017
@OsvaldoRosado OsvaldoRosado deleted the osrosado/fixcallercrash branch October 23, 2018 18:17
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.

4 participants