Skip to content

Commit 6bbec0f

Browse files
authored
Raise errors from threads in whitenoise.compress (#615)
1 parent 0b054e5 commit 6bbec0f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
Changelog
33
=========
44

5+
Unreleased
6+
----------
7+
8+
* Raise any errors from threads in the ``whitenoise.compress`` command.
9+
10+
Regression in 6.8.0.
11+
Thanks to Tom Grainger for the spotting this with a `comment on PR #484 <https://github.com/evansd/whitenoise/pull/484#discussion_r1818989096>`__.
12+
513
6.8.0 (2024-10-28)
614
------------------
715

src/whitenoise/compress.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
from concurrent.futures import ThreadPoolExecutor
8+
from concurrent.futures import as_completed
89
from io import BytesIO
910

1011
try:
@@ -181,12 +182,18 @@ def main(argv=None):
181182
)
182183

183184
with ThreadPoolExecutor() as executor:
185+
futures = []
184186
for dirpath, _dirs, files in os.walk(args.root):
185187
for filename in files:
186188
if compressor.should_compress(filename):
187-
executor.submit(
188-
compressor.compress, os.path.join(dirpath, filename)
189+
futures.append(
190+
executor.submit(
191+
compressor.compress, os.path.join(dirpath, filename)
192+
)
189193
)
194+
# Trigger any errors
195+
for future in as_completed(futures):
196+
future.result()
190197

191198
return 0
192199

tests/test_compress.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import shutil
88
import tempfile
9+
from unittest import mock
910

1011
import pytest
1112

@@ -84,3 +85,13 @@ def test_compressed_effectively_no_orig_size():
8485
assert not compressor.is_compressed_effectively(
8586
"test_encoding", "test_path", 0, "test_data"
8687
)
88+
89+
90+
def test_main_error(files_dir):
91+
with (
92+
pytest.raises(ValueError) as excinfo,
93+
mock.patch.object(Compressor, "compress", side_effect=ValueError("woops")),
94+
):
95+
compress_main([files_dir, "--quiet"])
96+
97+
assert excinfo.value.args == ("woops",)

0 commit comments

Comments
 (0)