diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-16 10:18:25 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2023-08-16 14:48:09 -0700 |
commit | f88a9cd6b374676e8f47da7137c8cd77c5bc2ccf (patch) | |
tree | 949a4d66e173e2e8d1251a62a833141b8711e3d9 | |
parent | 8a7fdd91599823e2d7e693ce8525ed833c6a8126 (diff) | |
download | meson-f88a9cd6b374676e8f47da7137c8cd77c5bc2ccf.zip meson-f88a9cd6b374676e8f47da7137c8cd77c5bc2ccf.tar.gz meson-f88a9cd6b374676e8f47da7137c8cd77c5bc2ccf.tar.bz2 |
fs.read(): Catch FileNotFoundError
-rw-r--r-- | mesonbuild/modules/fs.py | 4 | ||||
-rw-r--r-- | test cases/common/220 fs module/meson.build | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 7d96995..53174d2 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -261,8 +261,10 @@ class FSModule(ExtensionModule): try: with open(path, encoding=encoding) as f: data = f.read() + except FileNotFoundError: + raise MesonException(f'File {args[0]} does not exist.') except UnicodeDecodeError: - raise MesonException(f'decoding failed for {path}') + raise MesonException(f'decoding failed for {args[0]}') # Reconfigure when this file changes as it can contain data used by any # part of the build configuration (e.g. `project(..., version: # fs.read_file('VERSION')` or `configure_file(...)` diff --git a/test cases/common/220 fs module/meson.build b/test cases/common/220 fs module/meson.build index a1e9c44..b860fc8 100644 --- a/test cases/common/220 fs module/meson.build +++ b/test cases/common/220 fs module/meson.build @@ -142,3 +142,7 @@ assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compo subdir('subdir') subproject('subbie') + +testcase expect_error('File notfound does not exist.') + fs.read('notfound') +endtestcase |