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

feat: add uncaughtException handler #6011

Merged
merged 3 commits into from
Sep 19, 2023
Merged
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
36 changes: 31 additions & 5 deletions src/commands/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BANG, chalk, error, exit, log, NETLIFY_CYAN, USER_AGENT, warn } from '.
import execa from '../utils/execa.mjs'
import getGlobalConfig from '../utils/get-global-config.mjs'
import getPackageJson from '../utils/get-package-json.mjs'
import { track } from '../utils/telemetry/index.mjs'
import { track, reportError } from '../utils/telemetry/index.mjs'

import { createAddonsCommand } from './addons/index.mjs'
import { createApiCommand } from './api/index.mjs'
Expand All @@ -37,16 +37,42 @@ import { createWatchCommand } from './watch/index.mjs'

const SUGGESTION_TIMEOUT = 1e4

const getVersionPage = async () => {
// performance optimization - load envinfo on demand

const data = await envinfo.run({
process.on('uncaughtException', async (err) => {
console.log('')
lemusthelroy marked this conversation as resolved.
Show resolved Hide resolved
error(
`${chalk.red(
'Netlify CLI has terminated unexpectedly',
)}\nThis is a problem with the Netlify CLI, not with your application.\nIf you recently updated the CLI, consider reverting to an older version by running:\n\n${chalk.bold(
'npm install -g netlify-cli@VERSION',
)}\n\nYou can use any version from ${chalk.underline(
'https://ntl.fyi/cli-versions',
)}.\n\nPlease report this problem at ${chalk.underline(
'https://ntl.fyi/cli-error',
)} including the error details below.\n`,
{ exit: false },
)

const systemInfo = await getSystemInfo()

console.log(chalk.dim(err.stack || err))
console.log(chalk.dim(systemInfo))

reportError(err, { severity: 'error' })

process.exit(1)
})

const getSystemInfo = () =>
envinfo.run({
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmGlobalPackages: ['netlify-cli'],
})

const getVersionPage = async () => {
const data = await getSystemInfo()

return `
────────────────────┐
Environment Info │
Expand Down