From f88a9cd6b374676e8f47da7137c8cd77c5bc2ccf Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 16 Aug 2023 10:18:25 -0400 Subject: [PATCH] fs.read(): Catch FileNotFoundError --- mesonbuild/modules/fs.py | 4 +++- test cases/common/220 fs module/meson.build | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 7d9699588..53174d231 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 a1e9c44fc..b860fc8a3 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