-
-
Notifications
You must be signed in to change notification settings - Fork 810
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
Adding try/catch logic to Write-VcsStatus #170
Conversation
I've created two separate pull requests as they solve different bugs despite being in the same area of code, so not sure if you would want to accept none/one/both or they have different feedback and changes needed |
Sorry for the ridiculous delay in looking at these... I like the Once we get this nailed down, you might consider proposing an equivalent change to posh-hg. |
$VcsPromptStatusesVariableName = "VcsPromptStatuses" | ||
|
||
if (-not (Test-Path Variable:Global:$VcsPromptStatusesVariableName)) { | ||
New-Variable -Name $VcsPromptStatusesVariableName -Value @() -Scope Global |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why New-Variable ...
versus the simpler $Global:VcsPromptStatuses = ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relates more to the other proposed change, it was so the name of the global variable is controlled & set in one location, currently the $VcsPromptStatusesVariableName variable but potentially it could be set/changed from $GitPromptSettings
My mistake, I thought I had separated the two as they were done in separate branches. |
} | ||
if ($vcsPromptErrors.Length -gt 0) { | ||
# Log the errors but dont affect the users prompt, splat error objects into Write-Error | ||
$vcsPromptErrors | % { Write-Error -ErrorAction SilentlyContinue @_ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@_
?
New changes look good (other than |
4754915
to
37455a5
Compare
I've tweaked the history to remove the WIP & unrelated checkins so it is cleaner now 😀 I have replaced the using of the splat operator with just setting the ErrorRecord parameter to be the object.. Regardless of the type of exception thrown or what's sent to write-error they get changed into ErrorRecord objects so no need to map the object's properties onto the silent write-error call as I was doing. For now I've left in the functionality which detects and suppresses errors written to the errors stream/use of write-error.. It does complicate the function somewhat so let me know if you'd prefer to simplify it to only catch terminating exceptions. Off topic but related.. Posh-git, posh-hg and posh-svn all implement the same functions, has there been any discussion or thought on a provider agnostic base containing these common hooks so each provider repo can focus on its specific implementation details? |
14c1b55
to
f961b77
Compare
f961b77
to
4d95124
Compare
Adding try/catch logic to Write-VcsStatus so that if one of the scriptblocks that has been added to the VcsPromptStatuses array fails the other scriptblocks are still invoked and the effect on the user's prompt is minimized Use of the ErrorVariable parameter during invocation is to also capture any errors that were written to the error stream
Oops - I accidentally closed the PR while updating it with the latest changes 😊 Let me know if you're happy with the proposed implementation - I am in two minds about the detection & suppression of the error stream in addition to handling thrown exceptions.. |
Discussion? No. I tried to keep the That said, as a user of only posh-git I'm a very poor steward the multi-VCS situation (c.f. #111). If there's a clean way to extract a shared module on which all three could depend, I'm all for it (provided that manual, PsGet and Chocolatey installations keep working with minimal ceremony). |
Adding try/catch logic to Write-VcsStatus so that if one of the scriptblocks that has been added to the VcsPromptStatuses array fails the other scriptblocks are not affected (are still invoked) This complements the posh-git change dahlbyk/posh-git#170
@paulmarsy is this still something that you're struggling with? I don't object to the change in principle, but I let it get way out of date. 😞 |
Adding try/catch logic to Write-VcsStatus so that if one of the scriptblocks that has been added to the VcsPromptStatuses array fails the other scriptblocks are not affected (are still invoked)