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

[DIT-6379] Fix terminal hanging when Ctrl + C pressed during pull and token prompt #105

Merged
Show file tree
Hide file tree
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
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect - setting the exit code ensured that when the process exited of other means, it would have the specified status, but the intent of the quit() function in all instances of usage is to immediately terminate the running process.

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
Loading