Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($log): don't parse error stacks manually outside of IE/Edge #15767

Closed
wants to merge 2 commits into from

Conversation

mgol
Copy link
Member

@mgol mgol commented Mar 1, 2017

IE/Edge display errors in such a way that it requires the user to click in
4 places to see the stack trace. There is no way to feature-detect it so
there's a chance of the user agent sniffing to go wrong but since it's only
about logging, this shouldn't break apps. Other browsers display errors in
a sensible way and some of them map stack traces along source maps if available
so it makes sense to let browsers display it as they want.

Fixes #15590

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
Stack traces don't have source maps applied in any browser. The stack trace is formatted by Angular and printed as a string.

What is the new behavior (if this is a feature change)?
Stack traces have source maps applied in Chrome/Safari. The received error is printed as-is instead of printing a transformed stack trace.

Does this PR introduce a breaking change?
Maybe? The format of logged exceptions is not specified in the docs but there is a chance someone depends on it always being a string.

Please check if the PR fulfills these requirements

Other information:

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

A concern about a possible BC (for tests).
LGTM otherwise.

src/ng/log.js Outdated
// break apps. Other browsers display errors in a sensible way and some of them map stack
// traces along source maps if available so it makes sense to let browsers display it
// as they want.
if (arg.stack && (msie || /\bEdge\//.test($window.navigator.userAgent))) {
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT, this is adding a new requirement that mocking $window on tests (directly or indirectly) relying on $log.error() must include navigator.userAgent. This might break some tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be fixed by changing that into $window.navigator && $window.navigator.userAgent. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Works for me.

Also, I think it is a good idea to do this whole check once when instanciating the $log service:

var formatStackTrace = msie || ($window.navigator && /\bEdge\//.test($window.navigator.userAgent));

Copy link
Member Author

Choose a reason for hiding this comment

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

PR updated.

mgol added 2 commits March 2, 2017 11:35
IE/Edge display errors in such a way that it requires the user to click in
4 places to see the stack trace. There is no way to feature-detect it so
there's a chance of the user agent sniffing to go wrong but since it's only
about logging, this shouldn't break apps. Other browsers display errors in
a sensible way and some of them map stack traces along source maps if available
so it makes sense to let browsers display it as they want.

Fixes angular#15590
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM

@mgol mgol modified the milestones: 1.6.x, 1.7.0 Mar 3, 2017
@mgol mgol closed this in 3dc0096 Mar 3, 2017
@mgol mgol deleted the log-errors branch March 3, 2017 10:40
@mgol mgol modified the milestones: 1.6.3, 1.6.x Mar 3, 2017
mgol added a commit that referenced this pull request Mar 3, 2017
IE/Edge display errors in such a way that it requires the user to click in
4 places to see the stack trace. There is no way to feature-detect it so
there's a chance of the user agent sniffing to go wrong but since it's only
about logging, this shouldn't break apps. Other browsers display errors in
a sensible way and some of them map stack traces along source maps if available
so it makes sense to let browsers display it as they want.

Fixes #15590
Closes #15767
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
IE/Edge display errors in such a way that it requires the user to click in
4 places to see the stack trace. There is no way to feature-detect it so
there's a chance of the user agent sniffing to go wrong but since it's only
about logging, this shouldn't break apps. Other browsers display errors in
a sensible way and some of them map stack traces along source maps if available
so it makes sense to let browsers display it as they want.

Fixes angular#15590
Closes angular#15767
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No sourcemap-enabled stack trace in loadModules $injectorMinErr (at least not in Chrome)
4 participants