From e669acf9c7d6b94ad7500fdd974f8dd685d2e361 Mon Sep 17 00:00:00 2001 From: Jordin Gardner Date: Fri, 22 Mar 2024 09:28:50 -0700 Subject: [PATCH 1/2] fix: definitively exit CLI when quit() is called --- lib/init/token.ts | 17 ++++++++++++++++- lib/utils/quit.ts | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/init/token.ts b/lib/init/token.ts index ee906f2..c8aa5a0 100644 --- a/lib/init/token.ts +++ b/lib/init/token.ts @@ -1,4 +1,5 @@ import fs from "fs"; +import * as Sentry from "@sentry/node"; import chalk from "chalk"; @@ -132,7 +133,21 @@ export const collectAndSaveToken = async (message: string | null = null) => { config.saveToken(consts.CONFIG_FILE, consts.API_HOST, token); return token; } catch (error) { - quit("API token was not saved"); + // https://github.com/enquirer/enquirer/issues/225#issue-516043136 + // Empty string corresponds to the user hitting Ctrl + C + if (error === "") { + quit("", 0); + return; + } + + const eventId = Sentry.captureException(error); + const eventStr = `\n\nError ID: ${output.info(eventId)}`; + + return quit( + output.errorText( + "Something went wrong. Please contact support or try again later." + ) + eventStr + ); } }; diff --git a/lib/utils/quit.ts b/lib/utils/quit.ts index 526a5bc..355a0c0 100644 --- a/lib/utils/quit.ts +++ b/lib/utils/quit.ts @@ -1,4 +1,4 @@ export function quit(message: string | null, exitCode = 2) { if (message) console.log(`\n${message}\n`); - process.exitCode = exitCode; + process.exit(exitCode); } From 05358ccc87e28242b02bb87883ab25fb4e69f823 Mon Sep 17 00:00:00 2001 From: Jordin Gardner Date: Fri, 22 Mar 2024 09:31:47 -0700 Subject: [PATCH 2/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d64b5fb..19099ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dittowords/cli", - "version": "4.4.0", + "version": "4.4.1", "description": "Command Line Interface for Ditto (dittowords.com).", "license": "MIT", "main": "bin/index.js",