Skip to content

Commit

Permalink
Merge pull request #29 from LedgerHQ/fix
Browse files Browse the repository at this point in the history
[fix] Explicit management of 'ledger_app.toml' manifest not found
  • Loading branch information
lpascal-ledger authored Apr 30, 2024
2 parents 2596795 + 2ce0cac commit e6575cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ devices (NanoS, S+, X and Stax).

## Library sections

- [`ledger.utils.manifest` ](doc/manifest.md)
- [`ledger.manifest` ](doc/manifest.md)
16 changes: 15 additions & 1 deletion src/ledgered/github.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit e6575cc

Please sign in to comment.