Skip to content

Commit 865e7a1

Browse files
author
Lukas Holzer
authored
feat: add bugsnag reporting to the CLI application (#5640)
* feat: add bugsnag reporting to the CLI application * chore: only report error if it exits
1 parent 30d9a4f commit 865e7a1

File tree

12 files changed

+213
-75
lines changed

12 files changed

+213
-75
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, macOS-latest, windows-latest]
1616
node-version: ['14.18.0', '*']
17+
fail-fast: false
1718
steps:
1819
# Sets an output parameter if this is a release PR
1920
- name: Check for release

functions/error-reporting.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import process from 'process'
2+
3+
import Bugsnag from '@bugsnag/js'
4+
import { Handler } from '@netlify/functions'
5+
6+
Bugsnag.start({
7+
apiKey: `${process.env.NETLIFY_BUGSNAG_API_KEY}`,
8+
})
9+
10+
export const handler: Handler = async ({ body }) => {
11+
try {
12+
if (typeof body !== 'string') {
13+
return { statusCode: 200 }
14+
}
15+
const {
16+
cause,
17+
cliVersion,
18+
message,
19+
name,
20+
nodejsVersion,
21+
osName,
22+
severity = 'error',
23+
stack,
24+
user,
25+
} = JSON.parse(body)
26+
Bugsnag.notify({ name, message, stack, cause }, (event) => {
27+
event.setUser(user.id, user.email, user.name)
28+
event.severity = severity
29+
event.device = {
30+
osName,
31+
runtimeVersions: {
32+
nodejs: nodejsVersion,
33+
cli: cliVersion,
34+
},
35+
}
36+
})
37+
} catch (error) {
38+
Bugsnag.notify(error)
39+
}
40+
return {
41+
statusCode: 200,
42+
}
43+
}

netlify.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
to = "/.netlify/functions/telemetry"
2626
status = 200
2727
force = true
28+
[[redirects]]
29+
# Bugsnag link
30+
from = "/report-error"
31+
to = "/.netlify/functions/error-reporting"
32+
status = 200
33+
force = true
2834
[[redirects]]
2935
# Old CLI download links.
3036
from = "/download/latest/mac"

package-lock.json

Lines changed: 87 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"prettier": "--ignore-path .eslintignore --loglevel=warn \"{src,tools,scripts,site,tests,.github}/**/*.{mjs,cjs,js,md,yml,json,html}\" \"*.{mjs,cjs,js,yml,json,html}\" \".*.{mjs,cjs,js,yml,json,html}\" \"!CHANGELOG.md\" \"!**/*/package-lock.json\" \"!.github/**/*.md\""
7777
},
7878
"dependencies": {
79+
"@bugsnag/js": "^7.20.0",
7980
"@fastify/static": "^6.6.0",
8081
"@netlify/build": "^29.9.2",
8182
"@netlify/config": "^20.3.7",
@@ -186,6 +187,7 @@
186187
"devDependencies": {
187188
"@babel/preset-react": "^7.12.13",
188189
"@netlify/eslint-config-node": "^7.0.0",
190+
"@netlify/functions": "^1.4.0",
189191
"@types/fs-extra": "^11.0.1",
190192
"@types/prettyjson": "^0.0.30",
191193
"@vitest/coverage-c8": "^0.30.1",

0 commit comments

Comments
 (0)