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 prompt error stacktrace if Debug = $true #560

Merged
merged 2 commits into from
Apr 16, 2018
Merged

Add prompt error stacktrace if Debug = $true #560

merged 2 commits into from
Apr 16, 2018

Conversation

dahlbyk
Copy link
Owner

@dahlbyk dahlbyk commented Apr 14, 2018

To help troubleshoot errors like #558.

@@ -330,6 +330,10 @@ $PoshGitVcsPrompt = {
if ($s) {
Write-Prompt $s.BeforeText -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor
Write-Prompt "Error: $_" -BackgroundColor $s.ErrorBackgroundColor -ForegroundColor $s.ErrorForegroundColor
if ($s.Debug) {
Write-Host
Write-Verbose $_.ScriptStackTrace -Verbose
Copy link
Collaborator

@rkeithhill rkeithhill Apr 14, 2018

Choose a reason for hiding this comment

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

How about we change this line to:

                Write-Verbose "PoshGitVcsPrompt error details:" -Verbose
                Write-Verbose ($_ | Format-List * -Force | Out-String) -Verbose

Then we'd get more error info (including the script stacktrace) e.g.:

[PoshGitVcsPrompt error: kaboom]~\GitHub\dahlbyk\posh-git
04-14 12:15:30 280ms 2> $GitPromptSettings.Debug = $true

VERBOSE: 00010:Getting status
VERBOSE: 00060:Parsing status
VERBOSE: 00064:Status: ## rkeithhill/change-debugprompt...origin/rkeithhill/change-debugprompt
VERBOSE: 00066:Status:  M src/GitPrompt.ps1
VERBOSE: 00067:Building status object
VERBOSE: 00087:Finished
VERBOSE: PoshGitVcsPrompt error details:
VERBOSE:

PSMessageDetails      :
Exception             : System.Management.Automation.RuntimeException: kaboom
TargetObject          : kaboom
CategoryInfo          : OperationStopped: (kaboom:String) [], RuntimeException
FullyQualifiedErrorId : kaboom
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Write-GitWorkingDirStatusSummary, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\GitPrompt.ps1: line 776
                        at Write-GitStatus, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\GitPrompt.ps1: line 202
                        at <ScriptBlock>, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\GitPrompt.ps1: line 862
                        at <ScriptBlock>, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\GitPrompt.ps1: line 855
                        at Global:Write-VcsStatus, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\GitPrompt.ps1: line 855
                        at <ScriptBlock>, C:\Users\Keith\GitHub\dahlbyk\posh-git\src\posh-git.psm1: line 76
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

But note that this will note capture any errors in the built-in prompt function as that function calls this one.

Copy link
Owner Author

Choose a reason for hiding this comment

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

👍 consolidated into a single Write-Verbose for no particular reason.

But note that this will not capture any errors in the built-in prompt function as that function calls this one.

True. I'm content with this for 0.x; the prompt function changes substantially in 1.0 anyway.

Though it occurs to me that this whole change isn't all that useful as folks can just look at $Error to see what went wrong in either case. 🤷‍♂️

@rkeithhill
Copy link
Collaborator

RE $Error - that is true although the error of interest may not always be in $Error[0] so a little spelunking may be called for.

@dahlbyk dahlbyk merged commit ebb94fb into master Apr 16, 2018
@dahlbyk dahlbyk deleted the gh558 branch April 16, 2018 01:48
@dahlbyk dahlbyk added this to the v0.7.2 milestone Apr 17, 2018
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

Successfully merging this pull request may close these issues.

2 participants