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

Better error messages from git push #115

Merged
merged 2 commits into from
Feb 25, 2021
Merged

Better error messages from git push #115

merged 2 commits into from
Feb 25, 2021

Conversation

squaremo
Copy link
Member

libgit2 and go-git both have flaws in the way they treat errors from the remote. go-git takes only the first line, meaning that it gets a blank error message from GitLab which like to respond with a banner. libgit2 returns the whole response, including blank lines and fences ("=========...").

This commit corrects for both these flaws, by supplying a message if go-git has taken a blank line, and stripping out blank lines and fences from libgit2's error. This is unavoidably a brittle approach, so I have limited it to just the situation that was reported as a problem: pushing to the upstream git repo.

Fixes #102.

libgit2 and go-git both have flaws in the way they treat errors from
the remote. go-git takes only the first line, meaning that it gets a
blank error message from GitLab which like to respond with a
banner. libgit2 returns the whole response, including blank lines and
fences ("=========...").

This commit corrects for both these flaws, by supplying a message if
go-git has taken a blank line, and stripping out blank lines and
fences from libgit2's error. This is unavoidably a brittle approach,
so I have limited it to just the situation that was reported as a
problem: pushing to the upstream git repo.

Signed-off-by: Michael Bridgen <[email protected]>
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

Looks OK to me, tiny nit about a missing license header. 🍍

@@ -0,0 +1,86 @@
package controllers
Copy link
Member

Choose a reason for hiding this comment

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

Test file, but missing the LICENSE header we have everywhere.

This commit adds a handful of tests to make sure errors in the
problematic formats are rewritten, and other errors are left alone.

I'm reluctant to test against the actual git providers, since that
would introduce a dependency on them. Thus, these tests won't guard
against the providers changing their messages.

Signed-off-by: Michael Bridgen <[email protected]>
@squaremo squaremo merged commit a56b44b into main Feb 25, 2021
@squaremo squaremo deleted the better-push-message branch February 25, 2021 14:55
squaremo added a commit to fluxcd/pkg that referenced this pull request Mar 1, 2021
This adds the git error tidiers from

  fluxcd/image-automation-controller#115

to fluxcd/pkg/gitutil, so they can be used elsewhere e.g., in
source-controller.

Signed-off-by: Michael Bridgen <[email protected]>
squaremo added a commit to fluxcd/pkg that referenced this pull request Mar 2, 2021
This adds the git error tidiers from

  fluxcd/image-automation-controller#115

to fluxcd/pkg/gitutil, so they can be used elsewhere e.g., in
source-controller.

Signed-off-by: Michael Bridgen <[email protected]>
squaremo added a commit to fluxcd/source-controller that referenced this pull request Mar 3, 2021
In some circumstances (that are rather hard to reproduce), cloning
from a GitLab repo gets a multiline response as described in
fluxcd/image-automation-controller#115.

This uses the same remedy as in that PR, by calling the funcs provided
by fluxcd/pkg/gitutil on any error returned by libgit2 or gogit clone
operations.

Signed-off-by: Michael Bridgen <[email protected]>
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.

Image Automation not providing error message when git-repo has no write-access
2 participants