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

Tolerate stacktrace generation error when in strict mode #584

Merged
merged 4 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.browser
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN npm install --no-package-lock --no-save \

# install the dependencies and build each fixture
WORKDIR /app/test/browser/features/fixtures
RUN find . -path */package.json -type f -mindepth 2 -maxdepth 3 | \
RUN find . -name package.json -type f -mindepth 2 -maxdepth 3 | \
xargs -I % bash -c 'cd `dirname %` && npm install --no-package-lock && npm run build'

# once the fixtures are built we no longer need node_modules and
Expand Down
10 changes: 7 additions & 3 deletions packages/core/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ BugsnagReport.getStacktrace = function (error, errorFramesToSkip = 0, generatedF
} catch (e) {
if (hasStack(e)) return ErrorStackParser.parse(error).slice(1 + generatedFramesToSkip)
// error wasn't provided or didn't have a stacktrace so try to walk the callstack
return filter(StackGenerator.backtrace(), frame =>
(frame.functionName || '').indexOf('StackGenerator$$') === -1
).slice(1 + generatedFramesToSkip)
try {
return filter(StackGenerator.backtrace(), frame =>
(frame.functionName || '').indexOf('StackGenerator$$') === -1
).slice(1 + generatedFramesToSkip)
} catch (e) {
return []
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions test/browser/features/fixtures/strict_mode/script/a.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="module" src="/node_modules/@bugsnag/browser/dist/bugsnag.min.js"></script>
<script type="module">
var ENDPOINT = decodeURIComponent(window.location.search.match(/ENDPOINT=([^&]+)/)[1])
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
window.bugsnagClient = window.bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
})
</script>
</head>
<body>
<pre id="bugsnag-test-should-run">PENDING</pre>
<script nomodule>
var __lacksModuleSupport = true;
</script>
<script>
var el = document.getElementById('bugsnag-test-should-run')
el.textContent = el.innerText = typeof __lacksModuleSupport !== 'undefined' ? 'NO' : 'YES'
</script>
<script type="module">
var customError = {
name: 'Unlikely scenario',
stack: window.bugsnagClient.BugsnagReport.getStacktrace()
}
window.bugsnagClient.notify(customError)
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "bugsnag-js-fixtures-strict-mode-script",
"private": true,
"scripts": {
"build": "echo 'Done'"
},
"dependencies": {}
}
10 changes: 10 additions & 0 deletions test/browser/features/strict_mode.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@strict_mode
Feature: Compatibility with strict mode

Scenario: notifier does not error in strict mode
When I navigate to the URL "/strict_mode/script/a.html"
And the test should run in this browser
Then I wait to receive a request
And the request is a valid browser payload for the error reporting API
And the exception "errorClass" equals "Error"
And the exception "message" equals "Bugsnag usage error. notify() expected error/opts parameters, got unsupported object"