diff --git a/be/src/io/fs/local_file_system.cpp b/be/src/io/fs/local_file_system.cpp index fc2008a677..cf28c7caa0 100644 --- a/be/src/io/fs/local_file_system.cpp +++ b/be/src/io/fs/local_file_system.cpp @@ -203,23 +203,30 @@ Status LocalFileSystem::list_impl(const Path& dir, bool only_file, std::vectorpush_back(std::move(file_info)); } - files->push_back(std::move(file_info)); + } catch (const std::filesystem::filesystem_error& e) { + // although `directory_iterator(dir, ec)` does not throw an exception, + // it may throw an exception during iterator++, so we need to catch the exception here + return localfs_error(e.code(), fmt::format("failed to list {}, error message: {}", + dir.native(), e.what())); } if (ec) { return localfs_error(ec, fmt::format("failed to list {}", dir.native()));