[damned-lies] Avoid producing 500 errors for msginit failures
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Avoid producing 500 errors for msginit failures
- Date: Mon, 17 Jan 2022 08:01:52 +0000 (UTC)
commit d8250fd0754f2b31eb33559ed9abd867e1aca1ee
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Jan 17 09:01:19 2022 +0100
Avoid producing 500 errors for msginit failures
stats/tests/tests.py | 16 ++++++++++++++++
stats/views.py | 9 +++++++--
2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 1b8a0130..387e415a 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -374,6 +374,22 @@ class ModuleTestCase(TestCase):
)
self.assertContains(response, '# Tamil translation for gnome-hello.')
+ @test_scratchdir
+ def test_dynamic_po_msginit_error(self):
+ tamil = Language.objects.create(name="Tamil", locale="ta")
+ with PatchShellCommand(only=['git ']):
+ self.branch.update_stats(force=False) # At least POT stats needed
+ pot_stats = Statistics.objects.get(
+ branch=self.branch, domain__name='po', language__isnull=True
+ )
+ dyn_url = FakeLangStatistics(pot_stats, tamil).po_url()
+ with patch('stats.views.run_shell_command', side_effect=OSError()):
+ response = self.client.get(dyn_url)
+ self.assertContains(
+ response,
+ "Unable to produce a new .po file for language ta"
+ )
+
@test_scratchdir
def test_commit_ability(self):
branch = self.mod.get_head_branch()
diff --git a/stats/views.py b/stats/views.py
index ad6736b8..97a0f3dd 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -231,8 +231,13 @@ def dynamic_po(request, module_name, branch_name, domain_name, filename):
else:
dyn_content += "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n"
- command = "msginit --locale=%s --no-translator --input=%s --output-file=-" % (locale, file_path)
- status, output, err = run_shell_command(command, raise_on_error=True)
+ command = f"msginit --locale={locale} --no-translator --input={file_path} --output-file=-"
+ try:
+ status, output, err = run_shell_command(command, raise_on_error=True)
+ except OSError:
+ return HttpResponse(
+ f"Unable to produce a new .po file for language {locale}, msginit command failed."
+ )
lines = output.split("\n")
skip_next_line = False
for i, line in enumerate(lines):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]