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

feat: expanded missing command error, including 'did you mean' #6496

Merged
merged 9 commits into from May 15, 2023

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented May 2, 2023

Fixes #6492

For both the exec and run commands, adds a hint property based on a new buildCommandNotFoundHint utility.

Reuses the didyoumean2 package already used elsewhere in pnpm (and, fun fact, npm & yarn!).

Co-authored-by: Zoltan Kochan z@kochan.io

@welcome
Copy link

welcome bot commented May 2, 2023

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review May 2, 2023 20:06
@zkochan
Copy link
Member

zkochan commented May 2, 2023

Create a changeset

@zkochan
Copy link
Member

zkochan commented May 2, 2023

Looks like it doesn't work on Windows.

@zkochan
Copy link
Member

zkochan commented May 4, 2023

This is the error message on Windows:

Error: Command failed with exit code 1: xxxx
    at makeError (C:\Users\zolta\src\pnpm\pnpm\pnpm\dev\dist\pnpm.cjs:24357:17)
    at handlePromise (C:\Users\zolta\src\pnpm\pnpm\pnpm\dev\dist\pnpm.cjs:24928:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async C:\Users\zolta\src\pnpm\pnpm\pnpm\dev\dist\pnpm.cjs:207718:11 {
  shortMessage: 'Command failed with exit code 1: xxxx',
  command: 'xxxx',
  escapedCommand: 'xxxx',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

it doesn't have the original message. So, I am not sure how we can know the reason it failed.

I guess we could use which to see if the command exists

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as draft May 4, 2023 11:38
@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented May 4, 2023

(putting this into draft as I won't have a Windows computer for a few days)

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review May 13, 2023 19:22
@@ -208,6 +210,9 @@ export async function handler (
result[prefix].status = 'passed'
result[prefix].duration = getExecutionDuration(startTime)
} catch (err: any) { // eslint-disable-line
if (await isErrorCommandNotFound(params[0], err)) {
err.hint = buildCommandNotFoundHint(params[0], (await readProjectManifestOnly(opts.dir)).scripts)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 if I add an else after this locally, then the command properly throws err after setting err.hint. But without the else, we only get the exitCode = err.exitCode. Is there a reason to run the if (!opts.recursive ... check if we know the failure is from the command not being found?

@zkochan
Copy link
Member

zkochan commented May 14, 2023

The tests fail now because of @zkochan/which. I need to update my fork.

@zkochan zkochan merged commit ee429b3 into pnpm:main May 15, 2023
8 checks passed
@welcome
Copy link

welcome bot commented May 15, 2023

Congrats on merging your first pull request! 🎉🎉🎉

zkochan added a commit that referenced this pull request May 15, 2023
close #6492

Co-authored-by: Zoltan Kochan <z@kochan.io>
@JoshuaKGoldberg JoshuaKGoldberg deleted the exec-run-did-you-mean branch May 15, 2023 14:10
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.

More helpful message when command doesn't exist?
2 participants