cpp-common/bt2: use classes from `cpp-common/exc.hpp`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 30 May 2022 11:46:26 +0000 (07:46 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
This patch:

* Renames `lib-error.hpp` to `exc.hpp` as this could contain non-error
  exceptions in the future.

* Changes `bt2::Error`, `bt2::MemoryError`, and `bt2::OverflowError` to
  be aliases of `bt2_common::Error`, `bt2_common::MemoryError`, and
  `bt2_common::OverflowError`.

  This makes it possible for some code to catch only the common
  `bt2_common` errors to handle both library and user/internal
  exceptions.

  Note that those exceptions don't carry much information themselves;
  they're usually just a signal that an exception occurred, while the
  details are part of the libbabeltrace2 error of the current thread.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5bc1d39c8d978c21604614c68012509edc1776d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8176
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10824
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/clock-class.hpp
src/cpp-common/bt2/clock-snapshot.hpp
src/cpp-common/bt2/exc.hpp [new file with mode: 0644]
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field.hpp
src/cpp-common/bt2/integer-range-set.hpp
src/cpp-common/bt2/internal/utils.hpp
src/cpp-common/bt2/lib-error.hpp [deleted file]
src/cpp-common/bt2/message.hpp
src/cpp-common/bt2/trace-ir.hpp
src/cpp-common/bt2/value.hpp

index 8e45e2f2bf634a1c6eb3fc6de9b489d038f80a14..e80c8f9df0aad3a321a248e9d84bdc61f3ad5f8d 100644 (file)
@@ -18,7 +18,7 @@
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 #include "cpp-common/uuid-view.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 #include "value.hpp"
 
 namespace bt2 {
@@ -181,7 +181,7 @@ public:
         const auto status = bt_clock_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -208,7 +208,7 @@ public:
         const auto status = bt_clock_class_set_description(this->libObjPtr(), description);
 
         if (status == BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -271,7 +271,7 @@ public:
             bt_clock_class_cycles_to_ns_from_origin(this->libObjPtr(), value, &nsFromOrigin);
 
         if (status == BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
-            throw LibOverflowError {};
+            throw OverflowError {};
         }
 
         return nsFromOrigin;
index 9bd7a6d6fd3d7184c2996d5c1b10b005a478191b..643a229e1cdb3730bd4e04778c05e2b4b80f6876 100644 (file)
@@ -11,7 +11,7 @@
 #include <babeltrace2/babeltrace.h>
 
 #include "internal/borrowed-obj.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 
 namespace bt2 {
 
@@ -49,7 +49,7 @@ public:
         const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin);
 
         if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) {
-            throw LibOverflowError {};
+            throw OverflowError {};
         }
 
         return nsFromOrigin;
diff --git a/src/cpp-common/bt2/exc.hpp b/src/cpp-common/bt2/exc.hpp
new file mode 100644 (file)
index 0000000..4b57e43
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2020-2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_EXC_HPP
+#define BABELTRACE_CPP_COMMON_BT2_EXC_HPP
+
+#include <string>
+#include <stdexcept>
+
+#include "cpp-common/exc.hpp"
+
+namespace bt2 {
+
+using Error = bt2_common::Error;
+using OverflowError = bt2_common::OverflowError;
+using MemoryError = bt2_common::MemoryError;
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_EXC_HPP */
index 6460000ffe11c0dcda83fb0086777a63ee9edda8..536401c40dc61b8814e7936ddfea19948781da9e 100644 (file)
@@ -18,7 +18,7 @@
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 #include "common-iter.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 #include "integer-range-set.hpp"
 #include "field-path.hpp"
 #include "value.hpp"
@@ -886,7 +886,7 @@ public:
             this->libObjPtr(), label, ranges.libObjPtr());
 
         if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1175,7 +1175,7 @@ public:
             bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
 
         if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -2351,7 +2351,7 @@ public:
 
         if (status ==
             BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -2579,7 +2579,7 @@ public:
 
         if (status ==
             BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
index f1908b9923a84760d196deacdcd499b6d3c7ef47..126f8aa87aabd1eb5a8482c083bcf7f7f51871e2 100644 (file)
@@ -662,7 +662,7 @@ public:
                                                                              &labelArray, &count);
 
         if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return EnumerationFieldClassMappingLabels {labelArray, count};
@@ -743,7 +743,7 @@ public:
             bt_field_enumeration_signed_get_mapping_labels(this->libObjPtr(), &labelArray, &count);
 
         if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return EnumerationFieldClassMappingLabels {labelArray, count};
@@ -951,7 +951,7 @@ public:
         const auto status = bt_field_string_set_value(this->libObjPtr(), val);
 
         if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return *this;
@@ -1298,7 +1298,7 @@ public:
         const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length);
 
         if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 };
index 5889972d85ea6a596df90e923dcb05e96e433ada..a2cf119216bf2f6df008d3f7a5afc86199096eb0 100644 (file)
@@ -15,7 +15,7 @@
 #include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
 #include "integer-range.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 
 namespace bt2 {
 
@@ -226,7 +226,7 @@ public:
         const auto status = _Spec::addRange(this->libObjPtr(), lower, upper);
 
         if (status == BT_INTEGER_RANGE_SET_ADD_RANGE_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
index 34c52fffc883249cfc7b6330f8289fbde2b4cac6..7b162d12c28a268eb6a88df43008b9a3528518e1 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <type_traits>
 
-#include "../lib-error.hpp"
+#include "../exc.hpp"
 
 namespace bt2 {
 namespace internal {
@@ -18,7 +18,7 @@ template <typename LibObjPtrT>
 void validateCreatedObjPtr(const LibObjPtrT libOjbPtr)
 {
     if (!libOjbPtr) {
-        throw LibMemoryError {};
+        throw MemoryError {};
     }
 }
 
diff --git a/src/cpp-common/bt2/lib-error.hpp b/src/cpp-common/bt2/lib-error.hpp
deleted file mode 100644 (file)
index be8f800..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_BT2_LIB_ERROR_HPP
-#define BABELTRACE_CPP_COMMON_BT2_LIB_ERROR_HPP
-
-#include <string>
-#include <stdexcept>
-
-namespace bt2 {
-
-/*
- * Any library error.
- */
-class LibError : public std::runtime_error
-{
-public:
-    explicit LibError(const std::string& msg = "Error") : std::runtime_error {msg}
-    {
-    }
-};
-
-/*
- * Memory error.
- */
-class LibMemoryError : public LibError
-{
-public:
-    LibMemoryError() : LibError {"Memory error"}
-    {
-    }
-};
-
-/*
- * Overflow error.
- */
-class LibOverflowError : public LibError
-{
-public:
-    LibOverflowError() : LibError {"Overflow error"}
-    {
-    }
-};
-
-} /* namespace bt2 */
-
-#endif /* BABELTRACE_CPP_COMMON_BT2_LIB_ERROR_HPP */
index bc83c4b2181cbe9645bf5e9d1d9ab41ea2bfea08..5f6d376037c51caa99cc6e362ef55f125f9043e8 100644 (file)
@@ -19,7 +19,7 @@
 #include "internal/utils.hpp"
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 
 namespace bt2 {
 namespace internal {
index 625c3f33296563240fb18bec86b471a46b127674..5881092b384b1b2a12943149105dc1126fa903ce 100644 (file)
@@ -546,7 +546,7 @@ public:
         const auto status = bt_stream_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -768,7 +768,7 @@ public:
         const auto status = bt_trace_set_name(this->libObjPtr(), name);
 
         if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -848,7 +848,7 @@ public:
         const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -864,7 +864,7 @@ public:
         const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1121,7 +1121,7 @@ public:
         const auto status = bt_event_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1168,7 +1168,7 @@ public:
         const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
 
         if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1196,7 +1196,7 @@ public:
             bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1230,7 +1230,7 @@ public:
             bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1525,7 +1525,7 @@ public:
         const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1719,7 +1719,7 @@ public:
             bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1753,7 +1753,7 @@ public:
             bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
index a065af6c0c8715dec1c129847c6afde4c9d2ccb2..41bb4db52bfd899a54c2b49ab1f840c94fe740d2 100644 (file)
@@ -21,7 +21,7 @@
 #include "internal/utils.hpp"
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
 
 namespace bt2 {
 namespace internal {
@@ -696,7 +696,7 @@ public:
         const auto status = bt_value_string_set(this->libObjPtr(), rawVal);
 
         if (status == BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return *this;
@@ -947,7 +947,7 @@ private:
     void _handleAppendLibStatus(const bt_value_array_append_element_status status) const
     {
         if (status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 };
@@ -1034,7 +1034,7 @@ struct CommonMapValueSpec<bt_value> final
             return;
         case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR:
         case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR:
-            throw LibError {};
+            throw Error {};
         default:
             bt_common_abort();
         }
@@ -1067,7 +1067,7 @@ struct CommonMapValueSpec<const bt_value> final
             return;
         case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_USER_ERROR:
         case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR:
-            throw LibError {};
+            throw Error {};
         default:
             bt_common_abort();
         }
@@ -1286,7 +1286,7 @@ private:
     void _handleInsertLibStatus(const bt_value_map_insert_entry_status status) const
     {
         if (status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 };
This page took 0.033079 seconds and 4 git commands to generate.