Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ruyipkg): provide troubleshooting aid in case of fetch failures #49

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ruyi/ruyipkg/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SUPPORTED_CHECKSUM_KINDS = {"sha256", "sha512"}


def get_hash_instance(kind: str) -> hashlib._Hash:
def get_hash_instance(kind: str) -> "hashlib._Hash":
if kind not in SUPPORTED_CHECKSUM_KINDS:
raise ValueError(f"checksum algorithm {kind} not supported")
return hashlib.new(kind)
Expand Down
27 changes: 27 additions & 0 deletions ruyi/ruyipkg/distfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
from .unpack import do_unpack, do_unpack_or_symlink


# https://github.com/ruyisdk/ruyi/issues/46
HELP_ERROR_FETCHING = """
Downloads can fail for a multitude of reasons, most of which should not and
cannot be handled by [yellow]Ruyi[/yellow]. For your convenience though, please check if any
of the following common failure modes apply to you, and take actions
accordingly if one of them turns out to be the case:

* Basic connectivity problems
- is [yellow]the gateway[/yellow] reachable?
- is [yellow]common websites[/yellow] reachable?
- is there any [yellow]DNS pollution[/yellow]?
* Organizational and/or ISP restrictions
- is there a [yellow]firewall[/yellow] preventing Ruyi traffic?
- is your [yellow]ISP blocking access[/yellow] to the source website?
* Volatile upstream
- is the recorded [yellow]link dead[/yellow]? (Please raise a Ruyi issue for a fix!)
"""


class Distfile:
def __init__(
self,
Expand Down Expand Up @@ -61,6 +80,14 @@ def ensure_integrity_or_rm(self) -> bool:
return False

def fetch_and_ensure_integrity(self, *, resume: bool = False) -> None:
try:
return self._fetch_and_ensure_integrity(resume=resume)
except RuntimeError as e:
log.F(f"{e}")
log.stdout(HELP_ERROR_FETCHING)
raise SystemExit(1)

def _fetch_and_ensure_integrity(self, *, resume: bool = False) -> None:
fetcher = BaseFetcher.new(self.urls, self.dest)
fetcher.fetch(resume=resume)

Expand Down