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

Failure to cleanup masks real error when creating new project #8785

Closed
1 task done
Genteure opened this issue Oct 9, 2023 · 4 comments · Fixed by #8841
Closed
1 task done

Failure to cleanup masks real error when creating new project #8785

Genteure opened this issue Oct 9, 2023 · 4 comments · Fixed by #8841
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) needs response Issue needs response from OP pkg: create-astro Related to the `create-astro` package (scope)

Comments

@Genteure
Copy link
Contributor

Genteure commented Oct 9, 2023

Astro Info

Astro                    v3.2.3
Node                     v20.6.1
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

My workflow for creating new projects is:

  1. Create a new folder
  2. Open VSCode at the location
  3. Run scaffolding command in VSCode Terminal.

When pnpm create astro@latest fails to download the template, it throws a unhelpful error:

      ▲  error EBUSY: resource busy or locked, rmdir '.'

This error is not the real reason why it failed, it also brings question of "why are you trying to delete my directory?"

Reproduction steps:

  1. mkdir repro && code repro && cd repro, code repro can also be any other ways to lock the directory.
  2. Add 127.0.0.1 api.github.com to your hosts file, OR $env:HTTPS_PROXY="http://127.0.0.1:123456789", OR unplug your ethernet cable.
  3. Run pnpm create astro or it's equivalent.
  4. Type . when answering "Where should we create your new project?"

What's the expected result?

I would expect failure to cleanup be ignored, and the real reason it failed is written to the terminal.

try {
await downloadTemplate(templateTarget, {
force: true,
provider: 'github',
cwd: ctx.cwd,
dir: '.',
});
} catch (err: any) {
fs.rmdirSync(ctx.cwd);
if (err.message.includes('404')) {
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
} else {
throw new Error(err.message);
}
}

Link to Minimal Reproducible Example

N/A

Participation

  • I am willing to submit a pull request for this issue.
@lilnasy
Copy link
Contributor

lilnasy commented Oct 16, 2023

create-astro attempts to delete the folder it created when copying template fails. That is expected behavior. However, it might be assuming it had created the folder in this case.

Do you think it will be enough if it did not attempt deleting the folder when user input was .?

@lilnasy lilnasy added needs response Issue needs response from OP pkg: create-astro Related to the `create-astro` package (scope) - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Oct 16, 2023
@Genteure
Copy link
Contributor Author

Ohh that's a good idea, did not think of that. The user input could also be ./ so comparing current directory with the resolved path might be even better.

I still think the original error should be visible to the end user regardless whether rmdirSync failed or not. "Failed to delete directory" could be printed to the terminal in addition to the original error, if that's preferable.

@bluwy
Copy link
Member

bluwy commented Oct 17, 2023

I think we can skip if ctx.cwd is ., ./, or startsWith ../, which should cover most of the common cases. Adding error handling for rmdirSync would also be nice.

EDIT: it looks like logging an error for rmdirSync is a little tricky, so not doing that for now is fine by me.

@Genteure
Copy link
Contributor Author

I have added path check to PR #8841 and it's ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) needs response Issue needs response from OP pkg: create-astro Related to the `create-astro` package (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants