cpp-common/bt2c: Logger: factor out code to append cause
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 21 May 2024 16:43:47 +0000 (12:43 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Factor out the code that appends an error cause to a helper method, so
that it can be re-used.

Change-Id: I055314bef66968ef2ef30b5dd1728680d2f79c7c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12228
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2c/logging.hpp

index 2619152e9e73179b7647319fec48f53dba463376..bda68740e5c6c4ebe8d71363e0105491a090e41c 100644 (file)
@@ -294,6 +294,25 @@ public:
         return _mTextLocStrFmt;
     }
 
+    void appendCauseStr(const char * const fileName, const int lineNo, const char * const initMsg,
+                        const char * const msg) const noexcept
+    {
+        if (_mSelfMsgIter) {
+            bt_current_thread_error_append_cause_from_message_iterator(
+                _mSelfMsgIter->libObjPtr(), fileName, lineNo, "%s%s", initMsg, msg);
+        } else if (_mSelfComp) {
+            bt_current_thread_error_append_cause_from_component(_mSelfComp->libObjPtr(), fileName,
+                                                                lineNo, "%s%s", initMsg, msg);
+        } else if (_mSelfCompCls) {
+            bt_current_thread_error_append_cause_from_component_class(
+                _mSelfCompCls->libObjPtr(), fileName, lineNo, "%s%s", initMsg, msg);
+        } else {
+            BT_ASSERT(_mModuleName);
+            bt_current_thread_error_append_cause_from_unknown(_mModuleName->data(), fileName,
+                                                              lineNo, "%s%s", initMsg, msg);
+        }
+    }
+
 private:
     struct _StdLogWriter final
     {
@@ -534,20 +553,7 @@ private:
 
         /* Append an error cause if needed */
         if (AppendCauseV) {
-            if (_mSelfMsgIter) {
-                bt_current_thread_error_append_cause_from_message_iterator(
-                    _mSelfMsgIter->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
-            } else if (_mSelfComp) {
-                bt_current_thread_error_append_cause_from_component(
-                    _mSelfComp->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
-            } else if (_mSelfCompCls) {
-                bt_current_thread_error_append_cause_from_component_class(
-                    _mSelfCompCls->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
-            } else {
-                BT_ASSERT(_mModuleName);
-                bt_current_thread_error_append_cause_from_unknown(
-                    _mModuleName->data(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
-            }
+            this->appendCauseStr(fileName, lineNo, initMsg, _mBuf.data());
         }
     }
 
This page took 0.025355 seconds and 4 git commands to generate.