Skip to content

Conversation

@slarse
Copy link
Contributor

@slarse slarse commented Jul 22, 2021

@tohanss Here's the refactoring we looked at. I was gonna look it over again but I just didn't get around to it. Maybe you can make something of it.

Note that the core idea here was to have one form of error handling (here, we use exceptions). It would be equally valid to go with more monad-esque error handling and not throw exceptions. The important thing is to go with one kind.

@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #139 (2cfdabd) into master (9b5e599) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #139   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8        10    +2     
  Lines          255       285   +30     
  Branches        43        46    +3     
=========================================
+ Hits           255       285   +30     
Impacted Files Coverage Δ
repobee_sanitizer/_errorutils.py 100.00% <100.00%> (ø)
repobee_sanitizer/_gitutils.py 100.00% <100.00%> (ø)
repobee_sanitizer/_sanitize_repo.py 100.00% <100.00%> (ø)
repobee_sanitizer/sanitizer.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a7d648a...2cfdabd. Read the comment docs.

@tohanss tohanss force-pushed the refactor-sanitize branch from afdd90e to 9da5efc Compare July 23, 2021 15:27
@tohanss
Copy link
Contributor

tohanss commented Jul 23, 2021

Had to force push to remove an unrelated commit, no need to worry about that

@tohanss
Copy link
Contributor

tohanss commented Jul 23, 2021

Based on the number of deleted lines on this PR id say sanitizer was due for refactoring, not to mention if we make a PR for SanitizeFile as well. Most added lines are just git not understanding some things that were changed to be shorter.

@slarse i will make a second check tomorrow with fresh eyes, otherwise, this is ready for you to look at whenever you feel like it

Copy link
Contributor Author

@slarse slarse left a comment

Choose a reason for hiding this comment

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

Some minor comments

def sanitize_files(
basedir: pathlib.Path, file_relpaths: List[_fileutils.RelativePath]
) -> List[_format.FileWithErrors]:
):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omitting the type hint is not the same as stating that it returns None, as type hints themselves are optional. Omitting the type hint implicitly makes the type Any, which can be substituted for any type.

Suggested change
):
) -> None:

def sanitize_to_target_branch(
repo_path: pathlib.Path, target_branch: str, commit_message: str
) -> List[_format.FileWithErrors]:
):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
):
) -> None:

_syntax,
_format,
_gitutils,
sanitizer,
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 introduces a circular import. sanitizer imports _sanitize_repo, and vice versa. That's in general not a good sign, and can sometimes cause the program to not be able to execute at all (infinite import loop).

Comment on lines 26 to 29
class SanitizeError(plug.PlugError):
def __init__(self, msg: str, cause: Optional[Exception] = None):
self.msg = msg
super().__init__(msg, cause)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Put this somewhere else to avoid the circular import. Also, is this something that you want to be part of the "public API" of sanitizer (even though sanitizer isn't designed as a library)?

Comment on lines 89 to 92
status = plug.Status.SUCCESS
except SanitizeError as err:
result_message = err.msg
status = plug.Status.ERROR
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not just return directly in the try/except? That gives two very clear, very different exits (because they are very different, one is an error exit and the other one is a success exit).

Suggested change
status = plug.Status.SUCCESS
except SanitizeError as err:
result_message = err.msg
status = plug.Status.ERROR
return plug.Result(name="sanitize-repo", msg=result_message, status=plug.Status.SUCCESS)
except SanitizeError as err:
return plug.Result(name="sanitize-repo", msg=result_message, status=plug.Status.ERROR)

Copy link
Contributor

Choose a reason for hiding this comment

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

I felt one return statement was clearner. But when you think of them as completely different i think youre right

@slarse
Copy link
Contributor Author

slarse commented Aug 23, 2021

Will review this tonight.

Copy link
Contributor Author

@slarse slarse left a comment

Choose a reason for hiding this comment

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

Since this is actually my PR I can't approve it, but LGTM. I'd suggest fixing the test failures on master before merging though.

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