Some stuff from old exception-based error handling approach

This commit is contained in:
Ellwood Zwovic
2017-07-09 18:59:36 -07:00
parent d4a01350fd
commit f411c68115
3 changed files with 47 additions and 28 deletions

View File

@@ -10,7 +10,19 @@ import json
import logging
log = logging.getLogger(__name__)
# log.level = logging.DEBUG
class RepositoryError(Exception):
"""
Superclass for repository-related exceptions
"""
class MissingURLError(RepositoryError):
"""
Thrown when the repository needs a URL but doesn't have one
"""
# class RepositoryNotFound(
class Package:
"""
@@ -53,6 +65,12 @@ class Repository:
Requests repo.json from URL and embeds etag/last-modification headers
"""
log.debug(self.url)
if self.url is None:
raise MissingURLError("Cannot refresh repository without a URL")
log.debug("Refreshing repository from %s", self.url)
req_headers = {}
# Do things this way to avoid adding empty objects/None to the req_headers dict
@@ -110,19 +128,4 @@ class Repository:
json.dump(self.to_dict(), repo_file, indent=4, sort_keys=True)
log.info("repo.json written to %s" % path)
# def fetch_repo(url: str, repo: Repository) -> dict:
def refresh(url):
# we have to explicitly close the end of the pipe we are NOT using,
# otherwise no exception will be generated when the other process closes its end.
pipe[0].close()
local_repo_path = Path(__file__).parent / 'packages'
local_repo_path.mkdir(exist_ok=True)
try:
fetch_repojson(url)
pipe[1].send(re.status_code)
finally:
pipe[1].close()