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

bug: incorrect exit codes on failure #1033

Closed
jamesgeorge007 opened this issue Dec 30, 2022 · 2 comments · Fixed by #1043
Closed

bug: incorrect exit codes on failure #1033

jamesgeorge007 opened this issue Dec 30, 2022 · 2 comments · Fixed by #1043

Comments

@jamesgeorge007
Copy link

jamesgeorge007 commented Dec 30, 2022

Provide environment information

create-t3-app v6.11.6. Not including the environment information since this is directly related to the CLI.

Describe the bug

Aborting installation while scaffolding in a non-empty directory results in a 0 exit code. An instance of failure should ideally result in a non-zero exit code. Ref: lirantal/nodejs-cli-apps-best-practices#64-proper-use-of-exit-codes.

To reproduce

  • Create a new application on a path that exists and is non-empty.
  • Choose Abort installation at the prompt asking for overwrite confirmation. Alternatively, proceed with any of the other two options, and choose No at the next prompt.
  • Check the exit code - 0.

image

image

Additional information

I'd be happy to raise a PR 🙌

@c-ehrlich
Copy link
Member

Does choosing to exit the CLI because the folder already exists count as an "error"? It's an intentional choice by the user. I'm not super familiar with exit codes so need to research this one.

@jamesgeorge007
Copy link
Author

Does choosing to exit the CLI because the folder already exists count as an "error"? It's an intentional choice by the user.

I understand your point. But doesn't it count as a failed attempt while scaffolding a new project? Currently, it is signified by the spinner status set to fail.

if (overwriteDir === "abort") {
spinner.fail("Aborting installation...");
process.exit(0);
}

Consider a scenario in which the CLI is consumed in a CI environment; let's assume the existence of conflicting files isn't intended, and No is supplied if the prompt shows up, asking for the confirmation to overwrite. In this case, the job would succeed with the exit code being 0. However, we'd want the job would fail since the scaffolding didn't happen.

  • create-vue CLI handles it this way.

image

  • create-react-app and create-next-app returns with an exit code of 1 on encountering conflicting files. They don't handle directory cleanup.

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants