Skip to content

Commit

Permalink
Merge pull request #131 from openlawlibrary/renatav/error-handling
Browse files Browse the repository at this point in the history
Error handling and logging improvements
  • Loading branch information
danixeee authored May 12, 2020
2 parents 3cd427a + 22469ca commit 9e8df45
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 167 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning][semver].

### Changed

- Error handling and logging improvements ([131])

### Fixed

[131]: https://github.com/openlawlibrary/taf/pull/131

### Fixed


Expand Down
15 changes: 7 additions & 8 deletions taf/auth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from contextlib import contextmanager
from pathlib import Path
from tuf.repository_tool import METADATA_DIRECTORY_NAME
from taf.log import taf_logger
from taf.git import GitRepository, NamedGitRepository
from taf.repository_tool import (
Repository as TAFRepository,
Expand Down Expand Up @@ -49,6 +48,10 @@ def last_validated_commit(self):
except FileNotFoundError:
return None

@property
def log_prefix(self):
return f"Auth repo {self.name}: "

def get_target(self, target_name, commit=None, safely=True):
if commit is None:
commit = self.head_commit_sha()
Expand Down Expand Up @@ -99,9 +102,7 @@ def set_last_validated_commit(self, commit):
"""
Set the last validated commit of the authentication repository
"""
taf_logger.debug(
"Auth repo {}: setting last validated commit to: {}", self.name, commit
)
self._log_debug(f"setting last validated commit to: {commit}")
Path(self.conf_dir, self.LAST_VALIDATED_FILENAME).write_text(commit)

def sorted_commits_and_branches_per_repositories(self, commits):
Expand Down Expand Up @@ -133,10 +134,8 @@ def sorted_commits_and_branches_per_repositories(self, commits):
target_branch, []
).append(target_commit)
previous_commits[target_path] = target_commit
taf_logger.debug(
"Auth repo {}: new commits per repositories according to targets.json: {}",
self.name,
repositories_commits,
self._log_debug(
f"new commits per repositories according to targets.json: {repositories_commits}"
)
return repositories_commits

Expand Down
24 changes: 24 additions & 0 deletions taf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ def __init__(self, path):
self.message = f"Cannot fetch changes. Repo: {path}"


class GitError(TAFError):
def __init__(self, repo, command=None, error=None, message=None):
if message is None:
if command is not None:
message = f"error occurred while executing {command}"
if error is not None:
message = f"{message}:\n{error.output}"
elif error is not None:
message = error.output
else:
message = "error occurred"
self.message = f"{repo.log_prefix}{message}"
self.repo = repo
self.command = command
self.error = error


class InvalidBranchError(TAFError):
pass

Expand Down Expand Up @@ -45,6 +62,13 @@ class InvalidPINError(TAFError):
pass


class RepositoryInstantiationError(TAFError):
def __init__(self, repo_path, message):
super().__init__(f"Could not instantiate repository {repo_path}\n\n: {message}")
self.repo_path = repo_path
self.message = message


class MetadataUpdateError(TAFError):
def __init__(self, metadata_role, message):
super().__init__(
Expand Down
Loading

0 comments on commit 9e8df45

Please sign in to comment.