From 837524999bac4352134fdee84509a7dbf3865518 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 29 Jan 2023 18:56:24 -0700 Subject: [PATCH] fs: handle filesystem_error in directory_archive::load() we were hitting this on CI when attempting to load a texture called "light"; file_size() was throwing because it was attempting to get the file size of a directory called "light". --- common/fs.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/fs.cc b/common/fs.cc index 98dbeb19..47b2217a 100644 --- a/common/fs.cc +++ b/common/fs.cc @@ -48,11 +48,16 @@ struct directory_archive : archive_like return std::nullopt; } - uintmax_t size = file_size(p); - std::ifstream stream(p, std::ios_base::in | std::ios_base::binary); - std::vector data(size); - stream.read(reinterpret_cast(data.data()), size); - return data; + try { + uintmax_t size = file_size(p); + std::ifstream stream(p, std::ios_base::in | std::ios_base::binary); + std::vector data(size); + stream.read(reinterpret_cast(data.data()), size); + return data; + } catch (const filesystem_error &e) { + logging::funcprint("WARNING: {}\n", e.what()); + return std::nullopt; + } } };