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

fix(git): raise error if branch not found #220

Merged
merged 2 commits into from Sep 14, 2021

Conversation

dclayton-godaddy
Copy link
Contributor

To help us get this pull request reviewed and merged quickly, please be sure to include the following items:

  • Tests (if applicable)
  • Documentation (if applicable)
  • Changelog entry
  • A full explanation here in the PR description of the work done

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Backward Compatibility

Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the API in any way?

  • Yes (backward compatible)
  • No (breaking changes)

Issue Linking

What's new?

Currently, if someone runs the tartufo CLI using the --branch argument and the branch does not exist, the CLI will return no secrets found. This is misleading and should fail the call. This change will fail the call if --branch is specified and the branch was not found.

Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

I don't like the proposed name of the exception, but if you can sell @jwilhelm-godaddy on it I'll change my vote. ;-)

Comment on lines 614 to 616
raise BranchNotException(
f"Branch {self.git_options.branch} was not found."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, BranchNotException irks me because it feels like we're missing a word... the branch isn't what? Found? Valid?

Worse, I went and looked to see what tartufo was using for a convention, and they're pretty generic:

class TartufoException(Exception):
class ConfigException(TartufoException):
class ScanException(TartufoException):
class GitException(TartufoException):
class GitLocalException(GitException):
class GitRemoteException(GitException):

This makes me think we probably should be raising GitLocalException for a local repo or GitRemoteException for a remote repo, but I get that we probably don't want to have to screw around trying to pick the right one.

My suggestion here therefore would be to use GitBranchException (which should be a specialization of GitException).

The other option that came to mind would be some sort of UserFootInMouthException for when we are whining about GIGO directives, but there doesn't seem any call for it at this point so I'd stick with something simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not want to mark it as a GitException as it wasn't an issue interacting with Git (Raised if there is a problem interacting with git). This is a logic issue unrelated to interacting with git. For example, if someone typed in mybrach and missed the n, this is a user issue where it would say mybrach not found.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless of all else, I agree that BranchNotException doesn't particularly make sense. As @rbailey-godaddy said, it sounds like it's missing a word. I would recommend renaming it to BranchNotFoundException would be very appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol. You're right. Not sure what I was thinking. I changed to BranchNotFoundException.

tartufo/types.py Outdated
Comment on lines 106 to 107
class BranchNotException(TartufoException):
"""Raised if a branch was not found"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Per above, I'd make this GitBranchException(GitException) and you might need to move it down if this is ahead of the GitException declaration.

Copy link
Contributor

@sushantmimani sushantmimani left a comment

Choose a reason for hiding this comment

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

LGTM 🦅

@tarkatronic tarkatronic merged commit 02b43b5 into godaddy:main Sep 14, 2021
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.

None yet

4 participants