aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-05-11 10:35:51 +0200
committerWojtek Kosior <koszko@koszko.org>2022-05-11 11:12:24 +0200
commit98687e9148bac0a18bf6a62e672275af9a920d9c (patch)
treee9aea2c106f2b64bd09030322ec7214a813bb876
parent866922f80326671815c9187eed0ba6c4127b8721 (diff)
downloadhydrilla-builder-98687e9148bac0a18bf6a62e672275af9a920d9c.tar.gz
hydrilla-builder-98687e9148bac0a18bf6a62e672275af9a920d9c.zip
raise a more informative error when a file referenced from index.json is missing
-rw-r--r--src/hydrilla/builder/build.py7
-rw-r--r--src/hydrilla/builder/locales/en_US/LC_MESSAGES/hydrilla-messages.po40
-rw-r--r--tests/test_build.py2
3 files changed, 27 insertions, 22 deletions
diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py
index feecdfe..8354331 100644
--- a/src/hydrilla/builder/build.py
+++ b/src/hydrilla/builder/build.py
@@ -212,10 +212,11 @@ class Build:
file_ref = self.files_by_path.get(desired_path)
if file_ref is None:
- with open(path, 'rb') as file_handle:
- contents = file_handle.read()
+ if not path.is_file():
+ msg = _('referenced_file_{}_missing').format(desired_path)
+ raise FileReferenceError(msg)
- file_ref = FileRef(desired_path, contents)
+ file_ref = FileRef(desired_path, path.read_bytes())
self.files_by_path[desired_path] = file_ref
if include_in_distribution:
diff --git a/src/hydrilla/builder/locales/en_US/LC_MESSAGES/hydrilla-messages.po b/src/hydrilla/builder/locales/en_US/LC_MESSAGES/hydrilla-messages.po
index a6c6e83..807be87 100644
--- a/src/hydrilla/builder/locales/en_US/LC_MESSAGES/hydrilla-messages.po
+++ b/src/hydrilla/builder/locales/en_US/LC_MESSAGES/hydrilla-messages.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: hydrilla.builder 0.1.dev16+g4e46d7f.d20220211\n"
"Report-Msgid-Bugs-To: koszko@koszko.org\n"
-"POT-Creation-Date: 2022-05-10 16:47+0200\n"
+"POT-Creation-Date: 2022-05-11 11:10+0200\n"
"PO-Revision-Date: 2022-02-12 00:00+0000\n"
"Last-Translator: Wojtek Kosior <koszko@koszko.org>\n"
"Language: en_US\n"
@@ -18,13 +18,13 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.8.0\n"
-#: src/hydrilla/builder/build.py:86 src/hydrilla/builder/local_apt.py:117
-#: src/hydrilla/builder/local_apt.py:408
+#: src/hydrilla/builder/build.py:86 src/hydrilla/builder/local_apt.py:118
+#: src/hydrilla/builder/local_apt.py:407
msgid "couldnt_execute_{}_is_it_installed"
msgstr "Could not execute '{}'. Is the tool installed and reachable via PATH?"
-#: src/hydrilla/builder/build.py:90 src/hydrilla/builder/local_apt.py:121
-#: src/hydrilla/builder/local_apt.py:412
+#: src/hydrilla/builder/build.py:90 src/hydrilla/builder/local_apt.py:122
+#: src/hydrilla/builder/local_apt.py:411
msgid "command_{}_failed"
msgstr "The following command finished execution with a non-zero exit status: {}"
@@ -42,39 +42,43 @@ msgstr "Attempt to load '{}' which lies outside package source directory."
msgid "loading_reserved_index_json"
msgstr "Attempt to load 'index.json' which is a reserved filename."
-#: src/hydrilla/builder/build.py:350
+#: src/hydrilla/builder/build.py:216
+msgid "referenced_file_{}_missing"
+msgstr "Referenced file '{}' is missing."
+
+#: src/hydrilla/builder/build.py:351
msgid "report_spdx_not_in_copyright_list"
msgstr ""
"Told to generate 'report.spdx' but 'report.spdx' is not listed among "
"copyright files. Refusing to proceed."
-#: src/hydrilla/builder/build.py:421
+#: src/hydrilla/builder/build.py:422
msgid "build_package_from_srcdir_to_dstdir"
msgstr ""
"Build Hydrilla package from `scrdir` and write the resulting files under "
"`dstdir`."
-#: src/hydrilla/builder/build.py:423
+#: src/hydrilla/builder/build.py:424
msgid "source_directory_to_build_from"
msgstr "Source directory to build from."
-#: src/hydrilla/builder/build.py:425
+#: src/hydrilla/builder/build.py:426
msgid "path_instead_of_index_json"
msgstr ""
"Path to file to be processed instead of index.json (if not absolute, "
"resolved relative to srcdir)."
-#: src/hydrilla/builder/build.py:427
+#: src/hydrilla/builder/build.py:428
msgid "path_instead_for_piggyback_files"
msgstr ""
"Path to a non-standard directory with foreign packages' archive files to "
"use."
-#: src/hydrilla/builder/build.py:429
+#: src/hydrilla/builder/build.py:430
msgid "built_package_files_destination"
msgstr "Destination directory to write built package files to."
-#: src/hydrilla/builder/build.py:431
+#: src/hydrilla/builder/build.py:432
#, python-format
msgid "%(prog)s_%(version)s_license"
msgstr ""
@@ -85,7 +89,7 @@ msgstr ""
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law."
-#: src/hydrilla/builder/build.py:432
+#: src/hydrilla/builder/build.py:433
msgid "version_printing"
msgstr "Print version information and exit."
@@ -97,25 +101,25 @@ msgstr "## Command's standard output ##"
msgid "STDERR_OUTPUT_heading"
msgstr "## Command's standard error output ##"
-#: src/hydrilla/builder/local_apt.py:146
+#: src/hydrilla/builder/local_apt.py:147
msgid "distro_{}_unknown"
msgstr "Attempt to use an unknown software distribution '{}'."
-#: src/hydrilla/builder/local_apt.py:189
+#: src/hydrilla/builder/local_apt.py:190
msgid "couldnt_import_{}_is_it_installed"
msgstr ""
"Could not import '{}'. Is the module installed and visible to this Python"
" instance?"
-#: src/hydrilla/builder/local_apt.py:197
+#: src/hydrilla/builder/local_apt.py:198
msgid "gpg_couldnt_recv_key_{}"
msgstr "Could not import PGP key '{}'."
-#: src/hydrilla/builder/local_apt.py:314
+#: src/hydrilla/builder/local_apt.py:312
msgid "apt_install_output_not_understood"
msgstr "The output of an 'apt-get install' command was not understood."
-#: src/hydrilla/builder/local_apt.py:342
+#: src/hydrilla/builder/local_apt.py:338
msgid "apt_download_gave_bad_filename_{}"
msgstr "The 'apt-get download' command produced a file with unexpected name '{}'."
diff --git a/tests/test_build.py b/tests/test_build.py
index 77b1898..3d564e3 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -582,7 +582,7 @@ def sample_source_error_missing_file(monkeypatch, sample_source):
Modify index.json to expect missing report.spdx file and cause an error.
"""
monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report')
- return FileNotFoundError,
+ return FileReferenceError, '^referenced_file_report.spdx_missing$'
@error_maker
def sample_source_error_index_schema(monkeypatch, sample_source):