From 9cb0a9b680e85f5e59003b6aed8ad4b40f009463 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 1 Oct 2023 20:11:45 +0200 Subject: [PATCH] Library: discontinue setting error flag from Exceptions (see #1341) While seemingly subtle, this is a ''deep change.'' Up to now, the project attempted to maintain two mutually disjoint systems of error reporting: C-style error flags and C++ exceptions. Most notably, an attempt was made to keep both error states synced. During the recent integration efforts, this increasingly turned out as an obstacle and source for insidious problems (like deadlocks). As a resolve, hereby the relation of both systems is **clarified**: * C-style error flags shall only be set and used by C code henceforth * C++ exceptions can (optionally) be thrown by retrieving the C-style error code * but the opposite is now ''discontinued'' : Exceptions ''do not set'' the error flag anymore --- src/lib/allocation-cluster.cpp | 2 + src/lib/error-exception.cpp | 6 +-- src/lib/error.hpp | 2 +- src/stage/gtk-lumiera.cpp | 8 ++-- tests/10exception.tests | 3 +- tests/library/exception-error-test.cpp | 58 ++++---------------------- wiki/thinkPad.ichthyo.mm | 29 +++++++++++++ 7 files changed, 47 insertions(+), 61 deletions(-) diff --git a/src/lib/allocation-cluster.cpp b/src/lib/allocation-cluster.cpp index a6731aca1..865c74d02 100644 --- a/src/lib/allocation-cluster.cpp +++ b/src/lib/allocation-cluster.cpp @@ -213,6 +213,8 @@ namespace lib { catch (lumiera::Error & ex) { WARN (progress, "Exception while closing AllocationCluster: %s", ex.what()); + const char* errID = lumiera_error(); + TRACE (debugging, "Error flag was: %s", errID); } catch (...) { diff --git a/src/lib/error-exception.cpp b/src/lib/error-exception.cpp index 67b54a001..3320dcd06 100644 --- a/src/lib/error-exception.cpp +++ b/src/lib/error-exception.cpp @@ -96,16 +96,13 @@ namespace lumiera { - /** @note we set the C-style errorstate as a side effect */ Error::Error (string description, lumiera_err const id) noexcept : std::exception{} , id_{id} , msg_{error::default_usermsg (this)} , desc_{description} , cause_{} - { - lumiera_error_set (this->id_, description.c_str()); - } + { } Error::Error (std::exception const& cause, @@ -117,7 +114,6 @@ namespace lumiera { , cause_{extractCauseMsg(cause)} { string detailInfo{description + (isnil(cause_)? "" : " | cause = "+cause_)}; - lumiera_error_set (this->id_, detailInfo.c_str()); } diff --git a/src/lib/error.hpp b/src/lib/error.hpp index 1872b3166..32cb92afe 100644 --- a/src/lib/error.hpp +++ b/src/lib/error.hpp @@ -242,7 +242,7 @@ namespace lumiera { { throw error::Flag( error::detailInfo() , errorFlag); - } } //causes the error state to be set + } } /** Check the lumiera error state and throw a specific exception * in case a non-cleared errorflag is detected. No-op else. diff --git a/src/stage/gtk-lumiera.cpp b/src/stage/gtk-lumiera.cpp index 7bdf5170a..e9f1de535 100644 --- a/src/stage/gtk-lumiera.cpp +++ b/src/stage/gtk-lumiera.cpp @@ -154,10 +154,12 @@ namespace stage { } catch(...) { - if (!lumiera_error_peek()) - LUMIERA_ERROR_SET (stage, STATE, "unexpected error when starting the GUI thread"); + const char* errID = lumiera_error(); // clear C-style error flag + WARN (stage, "Unexpected error while starting the GUI thread."); + if (errID) + TRACE (stage, "Error flag was: %s", errID); return false; - } // note: lumiera_error state remains set + } } } // namespace stage diff --git a/tests/10exception.tests b/tests/10exception.tests index a2bafedf7..8fdbdf3c8 100644 --- a/tests/10exception.tests +++ b/tests/10exception.tests @@ -2,7 +2,7 @@ TESTING "Exception handling and diagnostics" ./test-suite --group=common -TEST "ExceptionError_test" ExceptionError_test < (msg); } + void detectErrorflag (string) { throwOnError(); } /** @test verify throwing of Exceptions @@ -169,12 +142,9 @@ namespace lumiera { lumiera_error_set(LERR_(LIFE_AND_UNIVERSE), "what is the answer?"); CHECK (lumiera_error_peek()); - catcher (&test::detectErrorflag, ""); - CHECK (LERR_(LIFE_AND_UNIVERSE) == lumiera_error_peek()); - - catcher (&test::detectErrorflagChained, "the big bang"); - CHECK (LERR_(LIFE_AND_UNIVERSE) == lumiera_error()); - } + catcher (&test::detectErrorflag); + CHECK (not lumiera_error_peek()); + }// yet translating that into an exception also clears the error flag /** @test the chaining of lumiera::Exception objects @@ -200,18 +170,6 @@ namespace lumiera { } - /** @test terminate the Application by throwing an undeclared exception. - * this should result in the global unknown() handler to be called, - * so usually it will terminate the test run. - * @note inside error.hpp, an initialisation hook has been installed into - * AppState, causing our own unknown() handler to be installed and - * invoked, which gives additional diagnostics.*/ - void terminateUnknown () noexcept - { - throw Error{"Catch the hedgehog..."}; - } - - /** a very specific Exception class * local to this scope and with * additional behaviour. @@ -238,7 +196,7 @@ namespace lumiera { /** helper: provides a bunch of catch-clauses and * runs the given member functions within */ - void catcher (void (ExceptionError_test::*funky)(string), string context) + void catcher (void (ExceptionError_test::*funky)(string), string context ="") { try { diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index db3895620..1f81ef8af 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -57360,6 +57360,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -80746,6 +80773,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ @@ -92193,6 +92221,7 @@ class Something +