From eaed9c2a2418fb968cb316836ce678a0ac9fe866 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Fri, 29 Sep 2023 16:40:42 +0200 Subject: [PATCH 1/3] Add `cargo::error_code::other` --- lib/cargo/error.hpp | 6 ++++++ lib/error.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/cargo/error.hpp b/lib/cargo/error.hpp index fe9ee86..598944b 100644 --- a/lib/cargo/error.hpp +++ b/lib/cargo/error.hpp @@ -44,6 +44,8 @@ class error_code { not_implemented = 2, no_such_transfer = 3, transfer_in_progress = 4, + /* ... */ + other = 127, }; public: @@ -52,6 +54,8 @@ public: static const error_code not_implemented; static const error_code no_such_transfer; static const error_code transfer_in_progress; + /* ... */ + static const error_code other; constexpr error_code() : error_code(error_value::success) {} constexpr explicit error_code(error_value v) @@ -99,6 +103,8 @@ constexpr error_code error_code::no_such_transfer{ error_value::no_such_transfer}; constexpr error_code error_code::transfer_in_progress{ error_value::transfer_in_progress}; +/* ... */ +constexpr error_code error_code::other{error_value::other}; static constexpr cargo::error_code make_system_error(std::uint32_t ec) { diff --git a/lib/error.cpp b/lib/error.cpp index 9987a45..851b575 100644 --- a/lib/error.cpp +++ b/lib/error.cpp @@ -281,6 +281,9 @@ error_code::name() const { return "CARGO_NO_SUCH_TRANSFER"; case error_value::transfer_in_progress: return "CARGO_TRANSFER_IN_PROGRESS"; + /* ... */ + case error_value::other: + return "CARGO_OTHER"; default: return "CARGO_UNKNOWN_ERROR"; } @@ -302,6 +305,9 @@ error_code::message() const { return "no such transfer"; case error_value::transfer_in_progress: return "transfer in progress"; + /* ... */ + case error_value::other: + return "other"; default: return "unknown error"; } -- GitLab From ce3637050fbb5b59275eb155cd3d431f27dbbe74 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Fri, 29 Sep 2023 16:41:04 +0200 Subject: [PATCH 2/3] Report previosly unhandled errors in workers 1. Catch `std::system_error`s, log them, and report them as Cargo system errors. 2. Catch and report `std:::exception`s, log them, and report them as Cargo `error_code::other` --- src/worker/mpio_read.cpp | 6 +++++- src/worker/mpio_write.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/worker/mpio_read.cpp b/src/worker/mpio_read.cpp index dedd284..1c6bbd0 100644 --- a/src/worker/mpio_read.cpp +++ b/src/worker/mpio_read.cpp @@ -144,8 +144,12 @@ mpio_read::operator()() const { } catch(const posix_file::io_error& e) { LOGGER_ERROR("{}() failed: {}", e.where(), e.what()); return make_system_error(e.error_code()); + } catch (const std::system_error& e) { + LOGGER_ERROR("Unexpected system error: {}", e.what()); + return make_system_error(e.code().value()); } catch(const std::exception& e) { - std::cerr << e.what() << '\n'; + LOGGER_ERROR("Unexpected exception: {}", e.what()); + return error_code::other; } return error_code::success; diff --git a/src/worker/mpio_write.cpp b/src/worker/mpio_write.cpp index 26cb812..5f40048 100644 --- a/src/worker/mpio_write.cpp +++ b/src/worker/mpio_write.cpp @@ -146,8 +146,12 @@ mpio_write::operator()() const { } catch(const posix_file::io_error& e) { LOGGER_ERROR("{}() failed: {}", e.where(), e.what()); return make_system_error(e.error_code()); + } catch (const std::system_error& e) { + LOGGER_ERROR("Unexpected system error: {}", e.what()); + return make_system_error(e.code().value()); } catch(const std::exception& e) { - std::cerr << e.what() << '\n'; + LOGGER_ERROR("Unexpected exception: {}", e.what()); + return error_code::other; } return error_code::success; -- GitLab From 49196d1dedff2b7ac0de94a2b1474fcdce549e99 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Fri, 29 Sep 2023 16:44:14 +0200 Subject: [PATCH 3/3] Improve reporting of errors in tests --- tests/tests.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/tests.cpp b/tests/tests.cpp index 6ec9d74..e2b2357 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -40,11 +40,15 @@ using namespace std::literals; using namespace std::chrono_literals; -std::ostream& -operator<<(std::ostream& os, const cargo::error_code& ec) { - os << ec.name(); - return os; -} +namespace Catch { +template <> +struct StringMaker { + static std::string + convert(const cargo::error_code& ec) { + return std::string{ec.name()}; + } +}; +} // namespace Catch CATCH_REGISTER_ENUM(cargo::transfer_state, cargo::transfer_state::pending, cargo::transfer_state::running, @@ -240,6 +244,7 @@ SCENARIO("Parallel reads", "[flex_stager][parallel_reads]") { // wait for the transfer to complete auto s = tx.wait(); + CAPTURE(s.error()); REQUIRE(s.state() == cargo::transfer_state::completed); REQUIRE(s.error() == cargo::error_code::success); @@ -301,6 +306,7 @@ SCENARIO("Parallel writes", "[flex_stager][parallel_writes]") { // wait for the transfer to complete auto s = tx.wait(); + CAPTURE(s.error()); REQUIRE(s.state() == cargo::transfer_state::completed); REQUIRE(s.error() == cargo::error_code::success); -- GitLab