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

Corepack "EACCES": Clearer Errors #343

Merged
merged 7 commits into from
Dec 29, 2023
Merged

Corepack "EACCES": Clearer Errors #343

merged 7 commits into from
Dec 29, 2023

Conversation

Medhansh404
Copy link
Contributor

#329
Targeted Error Handling: Code distinguishes between EEXIST (not relevant) and EACCES (triggers the specific error message), while other errors are still thrown for debugging.
Implementation: Changes are made in the getTemporaryFolder function within node_modules/corepack/dist/lib/corepack.cjs.
Testing: not done.

sources/folderUtils.ts Outdated Show resolved Hide resolved
sources/folderUtils.ts Outdated Show resolved Hide resolved
@@ -52,6 +53,8 @@ export function getTemporaryFolder(target: string = tmpdir()) {
} catch (error) {
if ((error as NodeError).code === `EEXIST`) {
continue;
} else if ((error as NodeError).code === `EACCES`) {
throw new UsageError(`Failed to create cache directory. Please ensure the user has write access to the target directory (${target}). If the user's home directory does not exist, create it first.`, {cause: error});
Copy link
Contributor

Choose a reason for hiding this comment

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

@arcanis it would maybe make sense to add support for this in Clipanion, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new UsageError(`Failed to create cache directory. Please ensure the user has write access to the target directory (${target}). If the user's home directory does not exist, create it first.`, {cause: error});
// @ts-expect-error UsageError expects one argument
throw new UsageError(`Failed to create cache directory. Please ensure the user has write access to the target directory (${target}). If the user's home directory does not exist, create it first.`, {cause: error});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now should we remove the cause: error?

@aduh95
Copy link
Contributor

aduh95 commented Dec 29, 2023

There are still lint errors to address.

@aduh95 aduh95 merged commit 518bed8 into nodejs:main Dec 29, 2023
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants