Skip to content

Running debugger against module manifest (psd1) file results in confusing error message #503

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

Closed
pcgeek86 opened this issue Feb 11, 2017 · 11 comments

Comments

@pcgeek86
Copy link
Contributor

If you hit F5 to invoke the debugger, and currently have a PowerShell module manifest file open, a confusing exception is thrown, and captured in the Visual Studio Code Debug Console.

Cannot run a document in the middle of a pipeline: c:\redacted\redacted.psd1.
At line:0 char:0

It'd be great to be able to set up multiple launch configurations, similar to how NPM works, so that hitting F5 isn't dependent on having the right file selected. For example, you might set up a launch configuration to invoke unit tests, or a separate one to publish the module to the PowerShell Gallery, etc. etc.

Cheers,
Trevor Sullivan
Docker Captain
Microsoft MVP: Cloud & Data Center Management
https://trevorsullivan.net
https://twitter.com/pcgeek86

@daviwil
Copy link
Contributor

daviwil commented Feb 11, 2017

You can already set up multiple launch configurations that launch specific file paths, but launching .psd1 files isn't currently supported. I'll either add support for it or add an appropriate error message.

@rkeithhill
Copy link
Contributor

You can set up multiple configurations. In the Debug view, press the gear icon to open your launch.json file. Now press the Add Configuration button and pick the "PowerShell: Launch Script" and fill in the script you want to launch.

@rkeithhill
Copy link
Contributor

rkeithhill commented Feb 11, 2017

Also, be sure to check out my Scripting Guys Debugging in VS Code Part 2 blog post that goes live on Monday. It covers this in a fair amount of detail.

@rkeithhill
Copy link
Contributor

And for launching Pester tests - see #487. It can be made to work now but I'm not sure I would rely on it - which is why I didn't add support yet.

@pcgeek86
Copy link
Contributor Author

Sounds good, thanks. I'd suggest keeping this open for the purposes of tracking "launching" a .psd1 file. What exactly would that do? I would maybe throw an exception, saying that you can't launch a .psd1, maybe? Not sure I have the best solution, but the current exception certainly isn't immediately helpful.

@daviwil
Copy link
Contributor

daviwil commented Feb 11, 2017

Ideally it'd just call Import-Module with that path and drop you into the console.

@rkeithhill
Copy link
Contributor

On the extension, do we have a chance to inspect the "script": arg before it gets sent to PSES? Either in VSCode or PSES we could test that A) the file exists (in case we allow an arg like Invoke-Pester which isn't a file) and if it is a file that exists B) has to have certain extension: .ps1, .psd1, .psm1 etc. Right now, it will try to launch against any file type (.md, .yml, .json, etc).

@daviwil
Copy link
Contributor

daviwil commented Feb 11, 2017

Yep, check out this function:

https://github.com/PowerShell/vscode-powershell/blob/develop/src/features/DebugSession.ts#L26

If you want to stop execution from happening, skip the vscode.commands.executeCommand('vscode.startDebug'...) call.

@rkeithhill
Copy link
Contributor

rkeithhill commented Feb 11, 2017

Should we initially not allow debugging of a .psd1 file? It's more of a data file and it might not even be a module manifest. It might be a string localization file. We could always come back later and enable .psd1 debugging.

@daviwil
Copy link
Contributor

daviwil commented Feb 11, 2017

Hmmm, good point. We can probably figure out whether it's a module manifest file, but not necessarily worth doing right now.

daviwil added a commit that referenced this issue Feb 18, 2017
…n-invalid-file-type

Fix #503 cancel debug on invalid file types.
@gabriel-vanca
Copy link

Why is this still not supported?

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

No branches or pull requests

4 participants