-
Notifications
You must be signed in to change notification settings - Fork 235
Prompt functions that return something other than string cause an InvalidCastException #339
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
Comments
Hmmm, I just tried setting a breakpoint in a test in |
Will do. I should have that by later tonight. |
1484702865-7a0f361c-6146-4030-afcc-c613a719e28c1484600221675.zip Here ya go. It looks like an exception in the posh-git prompt function might be at fault. |
Looks like the prompt function is returning a list of results rather than a string so it broke my prompt handling function. About to send a PR. |
So one thing this did point out to me is that I turned debugger prompts back on by default after we decided to turn them off in issue #130. The main reason for doing this was that I wanted the remote session / entered process prompt to be displayed so that it's obvious the user is in a non-default session. We currently don't have a better way to do that in the debug console. It looks alright until a prompt function causes an exception which makes us write out a "default" prompt function of I think there are two options:
Maybe a third option could be to write out a more obvious default prompt string? Any ideas there? |
I believe we still have some issues with the "default prompt" that posh-git installs. Regarding the prompt, I think that a "conventional prompt" isn't the right thing to display whether it's the user's prompt or one provided by PSES. I would find it useful to see what type of breakpoint was hit and at what location (file:line). So yes on # 3 if you can override the prompt function to display this information e.g.:
|
Hmmm, good point. Though this causes us to lose some of that session connection info if we don't spit out the prompt. Unfortunately I don't always have the necessary context to know when I'm in a remote session so that we only print it out when we're in a non-default session. And there's always the chance that the prompt function in any session could throw an error which would cause the prompt to be useless again. I'll have to think about this a little bit. |
So no way to override the session's prompt with one from the extension? I don't think you'd even need to bother to put it back to the original until we have the interactive console. |
I don't have to run the prompt function at all, I'm just trying to find a way to preserve the information that I can get from the prompt in the cases where I need it. Maybe I don't need it, but I'm still trying to decide whether it's more costly (or inevitable) to gather the information that I'd otherwise get from the default prompt. |
Many folks override their prompt in their global profile.ps1 file. And many I've seen don't bother checking if the session is currently stopped at a breakpoint (no What information are we trying to preserve? Path? That is the common thing displayed in the prompt. |
Nah, the session connection information, like |
And AFAIK those bits of info get written out by PowerShell regardless of what the user's prompt function returns. |
Oh that info. Yeah, that would be good to have. :-)
I believe that is correct since the default prompt does not have that info:
|
OK, I think I got it cleaned up pretty nicely, it looks like this now when you hit a breakpoint:
If you're stepping through the code no prompt will be written out because the stop wasn't caused by a breakpoint. If you run a command in the console, the real prompt will get written out after the command completes. I'm pretty happy with this solution, sending a PR in a minute. |
This change adds a catch for the InvalidCastException when gathering the user's prompt string in the case where their prompt function returns a value other than a string. In this case a default prompt is returned. This change also improves the way we write prompts for the debugger. Instead of writing out the prompt each time the debugger stops, we write out the details about the breakpoint that was hit, if any. We also try to preserve any session context at the beginning of the prompt string like the remote computer name or process ID. Fixes #339.
PR is here: #344 |
…eadingbacktick-rule Add PSMisleadingBacktick to PSSA settings file.
I was trying to debug some Pester tests while using latest PSES bits and was getting stymied by my breakpoints never getting hit. When I commented out the bundledModulesPath setting and went back to using 0.8.0, my breakpoints were hit.
Should be able to repro this with the Plaster repo, opening debugHarness.ps1 and uncommenting the code that invokes Pester. Set a breakpoint in one of the *.Tests.ps1 files and see if it gets hit.
The text was updated successfully, but these errors were encountered: