Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/cargomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,13 @@ def get_cargo_data(
if cargo_data is not None:
store_json(cargo_data, cargo_file)
return cargo_data
# TODO what happens when both backups fail?
# Download failed and no usable backup exists (typical on a
# fresh install when the wiki/GitHub cache is unreachable).
# Raise so the caller surfaces a real error instead of silently
# returning None — which would crash with TypeError further up.
raise RuntimeError(
f"Could not obtain cargo table '{filename}': download "
f"failed and no backup is available.")
else:
return self.get_cargo_data(filename, url, ignore_cache_age=True)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os import getenv as os__getenv
from pathlib import Path
from requests import Session
from requests.exceptions import Timeout
from requests.exceptions import RequestException
from time import time
from threading import Thread
from typing import Callable
Expand Down Expand Up @@ -93,7 +93,7 @@ def fetch_json(self, url: str) -> dict | list | None:
response.encoding = 'utf-8'
return json__loads(compensate_json(response.text))
return None
except (Timeout, JSONDecodeError):
except (RequestException, JSONDecodeError, ValueError):
return None

def download_cargo_table(self, url: str, file_name: str) -> dict | list | None:
Expand Down
15 changes: 13 additions & 2 deletions src/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class Thread(QThread):
"""
result: Signal = Signal(object)
done: Signal = Signal()
error: Signal = Signal(object)

def __init__(self, target: Callable, args: tuple = (), kwargs: dict[str] = {}):
super().__init__()
Expand All @@ -318,9 +319,19 @@ def set_args(self, new_args: tuple) -> bool:
def run(self):
"""
This function will be executed in a separate thread.

`done` is always emitted, even if the target raises, so callers waiting
on it (e.g. the splash screen) are never left hanging. Exceptions are
re-emitted via `error` so they can be logged or surfaced in the UI.
"""
self.result.emit(self._target(*self._args, **self._kwargs))
self.done.emit()
try:
self.result.emit(self._target(*self._args, **self._kwargs))
except BaseException as exc:
import traceback
traceback.print_exc()
self.error.emit(exc)
finally:
self.done.emit()


class ShipButton(QLabel):
Expand Down