From 18373a466b85ed0152cfa2e1e3947a415cc4dc59 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 15 May 2024 12:59:13 -0600 Subject: [PATCH] Preserving stdout to Download when singlefile fails. --- modules/archive/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/archive/__init__.py b/modules/archive/__init__.py index a5524cf2..7cd0d354 100644 --- a/modules/archive/__init__.py +++ b/modules/archive/__init__.py @@ -66,14 +66,14 @@ class ArchiveDownloader(Downloader, ABC): file_groups = list(session.query(FileGroup).filter(FileGroup.url.in_(urls), FileGroup.model == 'archive')) return file_groups - async def do_singlefile(self, download: Download) -> bytes: + async def do_singlefile(self, download: Download) -> Tuple[bytes, dict]: """Create a Singlefile from the archive's URL.""" cmd = (str(SINGLE_FILE_BIN), download.url, '--browser-executable-path', CHROMIUM, '--browser-args', '["--no-sandbox"]', '--dump-content') - return_code, _, stdout = await self.process_runner( + return_code, logs, stdout = await self.process_runner( download.id, download.url, cmd, @@ -82,7 +82,7 @@ class ArchiveDownloader(Downloader, ABC): if return_code != 0: raise RuntimeError(f'Archive singlefile exited with {return_code}') - return stdout + return stdout, logs async def do_readability(self, download: Download, html: bytes) -> dict: """Extract the readability dict from the provided HTML.""" @@ -127,9 +127,12 @@ class ArchiveDownloader(Downloader, ABC): @warning: Will not raise errors if readability or screenshot cannot be extracted. """ - singlefile = await self.do_singlefile(download) + singlefile, logs = await self.do_singlefile(download) if SINGLEFILE_HEADER.encode() not in singlefile[:1000]: + if logs and (stderr := logs.get('stderr') or ''): + e = RuntimeError(stderr) + raise RuntimeError(f'Singlefile created was invalid: {download.url}') from e raise RuntimeError(f'Singlefile created was invalid: {download.url}') # Extract Readability from the Singlefile.