diff --git a/src/commands/main.mjs b/src/commands/main.mjs index 94331869e01..0905df377e4 100644 --- a/src/commands/main.mjs +++ b/src/commands/main.mjs @@ -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' @@ -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('') + 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 │