fix(dl): exit 1 when a title's track download fails

This commit is contained in:
imSp4rky
2026-12-02 11:40:45 -07:00
parent 9842a61d3f
commit b1497c77a2
4 changed files with 88 additions and 6 deletions
+12 -5
View File
@@ -1239,8 +1239,8 @@ class dl:
self.archive_scope = "cli"
self.archive_cache: Path | None = None
# result() catches a download-worker failure, reports it, and returns rather than
# re-raising (so the CLI still exits cleanly). Keep it so an embedding caller (the API
# worker) can tell the title did not complete instead of reading it as a success.
# re-raising, so later code can tell the title did not complete: cli_result exits 1
# on it, and the API worker reads it from the outcome.
self.download_error: BaseException | None = None
if not config.output_template:
@@ -1500,7 +1500,14 @@ class dl:
# needs to be added this way instead of @cli.result_callback to be
# able to keep `self` as the first positional
self.cli._result_callback = self.result
self.cli._result_callback = self.cli_result
def cli_result(self, *args: Any, **kwargs: Any) -> RunOutcome:
"""Run :meth:`result` for the CLI and exit 1 when a download failed, unless a signal already stops the run."""
outcome = self.result(*args, **kwargs)
if outcome.error is not None and not process_exit.stopping():
sys.exit(1)
return outcome
def outcome(self) -> RunOutcome:
"""What the run gave back so far, for an embedding caller such as the API job."""
@@ -2400,8 +2407,8 @@ class dl:
self.export.log_summary()
return self.outcome()
except Exception as e: # noqa
# Reported and swallowed (no re-raise) so the CLI exits cleanly; keep it so the
# API worker sees the title failed rather than completing with no output.
# Reported and swallowed (no re-raise): cli_result exits 1 on it, and the API
# worker reads it from the outcome rather than completing with no output.
self.download_error = e
console.print(Padding(Group(*self.failure_lines(e)), (1, 5)))
if not isinstance(e, click.ClickException) and not retries_exhausted(e):
+1 -1
View File
@@ -459,7 +459,7 @@ def perform_download(
log.debug("Stderr: %s", stderr_capture.getvalue())
raise
# dl.result() reports a download-worker exception and returns normally, so the CLI exits cleanly.
# dl.result() reports a download-worker exception and returns it in the outcome, not raised.
if outcome.error is not None:
# segment URLs carry signed CDN tokens (hmac, session IDs) that redact_text does not match
detail = redact_all(dl_instance.failure_lines(outcome.error)[1].strip())