diff --git a/CHANGELOG.md b/CHANGELOG.md index a13a30b..fab02de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.7.1] - 2024-04-30 + +### Fixed + +- Clean error management when there is not `ledger_app.toml` manifest to access to on a given + repository/branch ## [0.7.0] - 2024-04-12 diff --git a/README.md b/README.md index 727bd76..906a418 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ devices (NanoS, S+, X and Stax). ## Library sections -- [`ledger.utils.manifest` ](doc/manifest.md) +- [`ledger.manifest` ](doc/manifest.md) diff --git a/src/ledgered/github.py b/src/ledgered/github.py index 822535a..0a39a4c 100644 --- a/src/ledgered/github.py +++ b/src/ledgered/github.py @@ -1,5 +1,6 @@ from enum import IntEnum, auto from github import ContentFile as PyContentFile, Github as PyGithub, Repository as PyRepository +from github.GithubException import UnknownObjectException from pathlib import Path from typing import List, Optional from unittest.mock import patch @@ -15,6 +16,13 @@ class Condition(IntEnum): ONLY = auto() +class NoManifestException(FileNotFoundError): + + def __init__(self, repository: "AppRepository"): + super().__init__(f"`ledger_app.toml` manifest not found in repository '{repository.url}', " + f"branch '{repository.current_branch}'.") + + class AppRepository(PyRepository.Repository): def __init__(self, *args, **kwargs) -> None: @@ -26,7 +34,13 @@ def __init__(self, *args, **kwargs) -> None: @property def manifest(self) -> Manifest: if self._manifest is None: - manifest = self.get_contents(MANIFEST_FILE_NAME, ref=self.current_branch) + try: + manifest = self.get_contents(MANIFEST_FILE_NAME, ref=self.current_branch) + except UnknownObjectException as e: + if e.status == 404: + raise NoManifestException(self) + raise e + # `get_contents` can return a list, but here there can only be one manifest assert isinstance(manifest, PyContentFile.ContentFile) manifest_content = manifest.decoded_content.decode()