Skip to content

Conversation

@asbjornu
Copy link
Member

@asbjornu asbjornu commented Apr 1, 2022

Add null guards to GitObject and ObjectId to avoid NullReferenceException.

Description

This PR is an exploration of which null guards we can add to avoid NullReferenceException and possibly also avoiding null before they reach GitVersion.Core.

Related Issue

Resolves #2775.

The following issues aren't fixed as this PR doesn't address the underlying issues, but this PR will provide a much more informative stack trace so if anyone encounters the underlying issues again, we'll have a better chance at figuring out what the issue is and actually fix it.

Closes #2605.
Closes #2631.
Closes #2695.
Closes #2734.
Closes #2825.

Motivation and Context

See #2775 and all linked issues.

How Has This Been Tested?

I'm counting on our existing test coverage to sufficiently exercise the code involved.

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@asbjornu asbjornu mentioned this pull request Apr 1, 2022
asbjornu added 3 commits April 2, 2022 22:33
- Add null check to GitRepository
- Also refactor the code a bit for readability
- Add various null checks to `RepositoryStore`.
- Also refactor the code a bit for readability.
@asbjornu asbjornu marked this pull request as ready for review April 2, 2022 20:57
@asbjornu asbjornu requested a review from arturcic April 2, 2022 20:57
@arturcic
Copy link
Member

arturcic commented Apr 4, 2022

Can you also add the null check for these classes? BranchCollection, Reference, TagCollection

Copy link
Member

@arturcic arturcic left a comment

Choose a reason for hiding this comment

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

LGTM

@arturcic
Copy link
Member

arturcic commented Apr 4, 2022

@asbjornu will you also add for the other 2?

@asbjornu
Copy link
Member Author

asbjornu commented Apr 4, 2022

@arturcic, yes, that's the plan. I just want every commit to be green so I'm confident that none of the added null checks break anything – and if they do, I want to know which one it is. But I'm unable to get a successful build out of 2790f27 due to some docker login failing. Ideas?

@asbjornu
Copy link
Member Author

asbjornu commented Apr 4, 2022

It's rather peculiar that the ❌ on the commit is red with lots of tests failing:

failing commit

…while the summary is all green ✅ :

successful summary

@arturcic
Copy link
Member

arturcic commented Apr 4, 2022

https://github.com/GitTools/GitVersion/actions/runs/2088880949 - this one seems to be green

@asbjornu
Copy link
Member Author

asbjornu commented Apr 4, 2022

Yea, I just want this ❌ green. 😅

image

I'll amend and force push, hopefully it turns green then.

asbjornu added 2 commits April 4, 2022 15:36
- Add various null checks to `BranchCollection`.
- Also refactor the code a bit for readability and improved stack traces.
@arturcic
Copy link
Member

arturcic commented Apr 4, 2022

I think it's failing on your branch on your repo, not on GtiTools, because it's trying to use some envvars that you do not have setup

@asbjornu
Copy link
Member Author

asbjornu commented Apr 4, 2022

Yes, that was my thought as well, @arturcic. But that doesn't explain why previous commits as well as the amended commit are all green? 🤔

successful commit

Anyway, as the commit is now successful, I'll continue pushing the other files as well.

@asbjornu asbjornu merged commit b601568 into GitTools:support/5.x Apr 4, 2022
@asbjornu asbjornu deleted the feature/gh-2825 branch April 4, 2022 19:29
@mergify
Copy link
Contributor

mergify bot commented Apr 4, 2022

Thank you @asbjornu for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment