Skip to content

Issue an actionable warning on CommandNotFoundException #491

@AnatoliB

Description

@AnatoliB

Problem
When users try to invoke a command that cannot be found in any modules, they get just the standard PowerShell error: The term 'xxx' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Sometimes they do get into this situation because of a typo, but very often this happens because they are missing modules, or because these modules don't work in PowerShell Core. It takes time and effort to realize that, and then it takes time and effort to figure out how to make the required modules available. Even though we have this documented, the documentation is not immediately discoverable, so new Function users spend more time and effort to invent their own ways, and sometimes come up with inefficient and difficult to support solutions.

Proposal

  • Detect this error during function execution and log a warning with suggestions and documentation links, something like: The app may be missing a module containing the 'xxx' command definition. If this command belongs to a module available on the PowerShell gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell Core 6 or PowerShell 7. For more details, see <doc link>. /cc @eamonoreilly for the message wording.
  • Consider going further: query the PS Gallery automatically and come up with a line of code to be inserted into requirements.psd1, include this line into the warning text.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions