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

Adding try/catch logic to Write-VcsStatus #170

Merged
merged 1 commit into from
Mar 12, 2017

Conversation

paulmarsy
Copy link
Contributor

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)

@paulmarsy
Copy link
Contributor Author

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

@dahlbyk
Copy link
Owner

dahlbyk commented May 14, 2015

Sorry for the ridiculous delay in looking at these... I like the try/catch to make Write-VcsStatus less destructive, but have concerns about the extra change for #169. If you can tease the changes apart, we can get this in first.

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
Copy link
Owner

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 = ...?

Copy link
Contributor Author

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

@paulmarsy
Copy link
Contributor Author

My mistake, I thought I had separated the two as they were done in separate branches.
I'll update this so it is purely the try/catch logic change 😄

@paulmarsy
Copy link
Contributor Author

The last two commits (b6dd6ea and 4754915) detect errors written to the error stream as well as terminating exceptions which are thrown.

Let me know if you'd prefer them to be removed, as they detect non-terminating errors it may be better to continue as per normal.

}
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 @_ }
Copy link
Owner

Choose a reason for hiding this comment

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

@_?

@dahlbyk
Copy link
Owner

dahlbyk commented May 20, 2015

New changes look good (other than @_) - can you do me a favor and rebase on master without the unrelated commits?

@paulmarsy paulmarsy force-pushed the WriteVcsStatus-bug branch from 4754915 to 37455a5 Compare May 21, 2015 23:45
@paulmarsy
Copy link
Contributor Author

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.
If that is your preference I'll leave the current commit in the history for reference in the incase it may be useful somewhere else.

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?

@paulmarsy paulmarsy force-pushed the WriteVcsStatus-bug branch from 14c1b55 to f961b77 Compare May 22, 2015 20:36
@paulmarsy paulmarsy closed this May 22, 2015
@paulmarsy paulmarsy force-pushed the WriteVcsStatus-bug branch from f961b77 to 4d95124 Compare May 22, 2015 20:37
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
@paulmarsy paulmarsy reopened this May 22, 2015
@paulmarsy
Copy link
Contributor Author

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..
It complicates the error handling logic & function, but does provide an extra layer of error handling invoked code which can be external to posh-git..

@dahlbyk
Copy link
Owner

dahlbyk commented May 23, 2015

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?

Discussion? No. I tried to keep the Write-VcsStatus logic simple specifically to keep our shared surface area small, allowing independent evolution as necessary. To that end, my first instinct here is to just mandate that the subscribed status writers guarantee they won't throw so we can keep the copy-pasta simple.

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).

ghost pushed a commit to TSYS-Merchant/posh-svn that referenced this pull request Mar 11, 2016
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
@dahlbyk
Copy link
Owner

dahlbyk commented Dec 31, 2016

@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. 😞

@dahlbyk dahlbyk added this to the Ideas milestone Feb 6, 2017
@dahlbyk dahlbyk merged commit 2eb11c2 into dahlbyk:master Mar 12, 2017
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