SeeminglyScience/EditorServicesCommandSuite

Improve ConvertTo-SplatExpression error message when cursor position is not within a command.

Opened this issue · 2 comments

Right now the error message is this:

ConvertTo-SplatExpression : Unable to find an AST of type 'CommandAst' at the specified location.
At line:1 char:1
+ ConvertTo-SplatExpression
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [ConvertTo-SplatExpression], ArgumentException
+ FullyQualifiedErrorId : MissingAst,ConvertTo-SplatExpression

Which is pretty meaningless to most people. Should be something like "Unable to determine which command to splat. Ensure the cursor is placed within a command and try again."

I should also check for active selections and look for CommandAst's anywhere within.

Thank you @jkavanagh58!

Thank you sir, definitely operator error but a more descriptive error may have kept me from performing the same action expecting different behavior. 🤕

There's a few improvements coming in 0.5.0 that make this a bit easier to use

  1. If your cursor is directly after the command AST it'll pick that up
  2. It'll recurse parent ASTs to find the most likely target when your cursor is within nested expressions