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

Add informative message for missing executable on Windows #2291

Conversation

shadowspawn
Copy link
Collaborator

Problem

There is an informative runtime message to help the author when fail to find a stand-alone subcommand, but the message does not appear on Windows.

See: #2290

Solution

Windows always tries opening the executable as an argument to node. Test for the existence of the file first.

ChangeLog

  • add: show informative error on Windows for missing stand-alone executable subcommand

@shadowspawn shadowspawn marked this pull request as draft December 5, 2024 23:41
@shadowspawn shadowspawn force-pushed the feature/missing-executable-message-on-windows branch from 28966a8 to 8762e44 Compare December 6, 2024 00:17
@shadowspawn shadowspawn marked this pull request as ready for review December 6, 2024 01:38
@shadowspawn
Copy link
Collaborator Author

Ouch. The new failure mode was hard to get working with the existing tests, but refactoring into a separate routine allowed suppressing the behaviour so existing tests could stay much the same.

@shadowspawn shadowspawn changed the base branch from develop to release/13.x December 6, 2024 01:44
lib/command.js Outdated
* @param {string} executableDir
* @param {string} subcommandName
*/
_throwForMissingExecutable(executableFile, executableDir, subcommandName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The method name is _throwForMissingExecutable, but it may not throw, so why not name it something like _validateExecutable?

Or how about doing the checks outside of the method?

if (!fs.existsSync(executableFile)) {
 _throwForMissingExecutable(...);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

method name

Oh, yes. I originally had the check outside the routine. Will change name.

Or how about doing the checks outside of the method?

I agree that would be tidier for the code and usage. However, I started that way, and multiple unit tests check whether fs.existsSync has been called and broke. I didn't think of an easy way of fixing the tests, other than moving the fs. fs.existsSync inside the routine. Then easy to completely bypass the new code and run the old tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have several _checkForX routines already so following that style, _checkForMissingExecutable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lots!

  • _checkForMissingMandatoryOptions
  • _checkForConflictingLocalOptions
  • _checkForConflictingOptions
  • _checkForBrokenPassThrough

@shadowspawn shadowspawn merged commit a8ef5cf into tj:release/13.x Dec 8, 2024
9 checks passed
@shadowspawn shadowspawn deleted the feature/missing-executable-message-on-windows branch December 8, 2024 01:47
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending release Merged into a branch for a future release, but not released yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants