fs.read(): Catch FileNotFoundError

pull/11870/merge
Xavier Claessens 1 year ago committed by Jussi Pakkanen
parent 8a7fdd9159
commit f88a9cd6b3
  1. 4
      mesonbuild/modules/fs.py
  2. 4
      test cases/common/220 fs module/meson.build

@ -261,8 +261,10 @@ class FSModule(ExtensionModule):
try: try:
with open(path, encoding=encoding) as f: with open(path, encoding=encoding) as f:
data = f.read() data = f.read()
except FileNotFoundError:
raise MesonException(f'File {args[0]} does not exist.')
except UnicodeDecodeError: 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 # Reconfigure when this file changes as it can contain data used by any
# part of the build configuration (e.g. `project(..., version: # part of the build configuration (e.g. `project(..., version:
# fs.read_file('VERSION')` or `configure_file(...)` # fs.read_file('VERSION')` or `configure_file(...)`

@ -142,3 +142,7 @@ assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compo
subdir('subdir') subdir('subdir')
subproject('subbie') subproject('subbie')
testcase expect_error('File notfound does not exist.')
fs.read('notfound')
endtestcase

Loading…
Cancel
Save