Skip to content

Commit

Permalink
[DIT-6379] Fix terminal hanging when Ctrl + C pressed during pull a…
Browse files Browse the repository at this point in the history
…nd token prompt (#105)

* fix: definitively exit CLI when quit() is called

* bump version

---------

Co-authored-by: Jordin Gardner <[email protected]>
  • Loading branch information
azjgard and azjgard authored Mar 22, 2024
1 parent b77c407 commit 0932396
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/init/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import * as Sentry from "@sentry/node";

import chalk from "chalk";

Expand Down Expand Up @@ -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
);
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/quit.ts
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0932396

Please sign in to comment.