Wrap calls to fmt::format to catch formatting exceptions
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Jun 2023 18:53:15 +0000 (14:53 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Jun 2023 19:18:08 +0000 (15:18 -0400)
fmt::format throws when a formatting error is encountered.
Unfortunately, we can't ensure complete coverage of all logging call
sites (e.g. error paths) and it is not desirable for such an exception
to be thrown in those cases.

The formatting error is returned as the formatted string so that it ends
up in the logs or exception messages more or less transparently.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1cb33a5fe87221139eaf9de918b47e0397daa89c

18 files changed:
src/bin/lttng-sessiond/ctf2-trace-class-visitor.cpp
src/bin/lttng-sessiond/field.cpp
src/bin/lttng-sessiond/field.hpp
src/bin/lttng-sessiond/rotation-thread.cpp
src/bin/lttng-sessiond/tsdl-trace-class-visitor.cpp
src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-field-convert.cpp
src/bin/lttng-sessiond/ust-registry-channel.cpp
src/bin/lttng-sessiond/ust-registry-session.cpp
src/bin/lttng/commands/destroy.cpp
src/bin/lttng/commands/start.cpp
src/bin/lttng/commands/stop.cpp
src/common/container-wrapper.hpp
src/common/error.hpp
src/common/eventfd.cpp
src/common/file-descriptor.cpp
src/common/format.hpp
src/common/random.cpp

index 24fe15792545f43c38120d803e56d81f51fa46ce..8da98591d6e0c731eea61d67199a8c859cef6b72 100644 (file)
@@ -205,8 +205,8 @@ private:
                        if (std::is_signed<typename EnumerationType::mapping::range_t::
                                                   range_integer_t>::value) {
                                LTTNG_THROW_ERROR(
-                                       fmt::format("Failed to serialize {}: unexpected role",
-                                                   _fragment["type"]));
+                                       lttng::format("Failed to serialize {}: unexpected role",
+                                                     _fragment["type"]));
                        }
 
                        auto role_array = json::json::array();
@@ -219,7 +219,7 @@ private:
                }
 
                if (type.mappings_->size() < 1) {
-                       LTTNG_THROW_ERROR(fmt::format(
+                       LTTNG_THROW_ERROR(lttng::format(
                                "Failed to serialize {}: enumeration must have at least one mapping",
                                _fragment["type"]));
                }
index 2d7f9deaca9c89b9f7916ace43407272fbc83918..94d002167556a87fe3901359a25d9f28d49c4872 100644 (file)
@@ -65,8 +65,8 @@ lst::field::field(std::string in_name, lst::type::cuptr in_type) :
        name{ std::move(in_name) }, _type{ std::move(in_type) }
 {
        if (!_type) {
-               LTTNG_THROW_ERROR(
-                       fmt::format("Invalid type used to create field: field name = `{}`", name));
+               LTTNG_THROW_ERROR(lttng::format(
+                       "Invalid type used to create field: field name = `{}`", name));
        }
 }
 
@@ -90,7 +90,7 @@ const lst::type& lst::field::get_type() const
        if (_type) {
                return *_type;
        } else {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Invalid attempt to access field type after transfer: field name = `{}`",
                        name));
        }
@@ -162,7 +162,7 @@ lst::floating_point_type::floating_point_type(unsigned int in_alignment,
                return;
        }
 
-       LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+       LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                "Invalid exponent/mantissa values provided while creating {}", typeid(*this)));
 }
 
index 8ba85d81a9efc2ed5bd2bb72808a0b54cea4947a..5180574a1c0cb721aa175cec0d818e7481cd9ddf 100644 (file)
@@ -638,9 +638,9 @@ template <typename MappingIntegerType>
                                   MappingIntegerType>::mapping::range_t range)
 {
        if (range.begin == range.end) {
-               return ::fmt::format("[{}]", range.begin);
+               return ::lttng::format("[{}]", range.begin);
        } else {
-               return ::fmt::format("[{}, {}]", range.begin, range.end);
+               return ::lttng::format("[{}, {}]", range.begin, range.end);
        }
 }
 } /* namespace details */
index 10afaa649770139abd7d359fcb37c7114f79d0bf..1d62c851ee3b57038d35d692363d3998b3f1d4ff 100644 (file)
@@ -752,8 +752,8 @@ void ls::rotation_thread::_run()
                        DBG_FMT("Handling descriptor activity: fd={}, events={:b}", fd, revents);
 
                        if (revents & LPOLLERR) {
-                               LTTNG_THROW_ERROR(
-                                       fmt::format("Polling returned an error on fd: fd={}", fd));
+                               LTTNG_THROW_ERROR(lttng::format(
+                                       "Polling returned an error on fd: fd={}", fd));
                        }
 
                        if (fd == _notification_channel->socket ||
@@ -789,7 +789,7 @@ void ls::rotation_thread::_run()
 
                                        if (lttng_read(fd, &buf, 1) != 1) {
                                                LTTNG_THROW_POSIX(
-                                                       fmt::format(
+                                                       lttng::format(
                                                                "Failed to read from wakeup pipe: fd={}",
                                                                fd),
                                                        errno);
@@ -849,14 +849,14 @@ void ls::rotation_thread::subscribe_session_consumed_size_rotation(ltt_session&
        auto condition_status =
                lttng_condition_session_consumed_size_set_threshold(rotate_condition.get(), size);
        if (condition_status != LTTNG_CONDITION_STATUS_OK) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Could not set session consumed size condition threshold: size={}", size));
        }
 
        condition_status = lttng_condition_session_consumed_size_set_session_name(
                rotate_condition.get(), session.name);
        if (condition_status != LTTNG_CONDITION_STATUS_OK) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Could not set session consumed size condition session name: name=`{}`",
                        session.name));
        }
@@ -895,7 +895,7 @@ void ls::rotation_thread::subscribe_session_consumed_size_rotation(ltt_session&
                &_notification_thread_handle, trigger.get(), true);
        if (register_ret != LTTNG_OK) {
                LTTNG_THROW_CTL(
-                       fmt::format(
+                       lttng::format(
                                "Failed to register trigger for automatic size-based rotation: session_name{}, size={}",
                                session.name,
                                size),
@@ -919,7 +919,7 @@ void ls::rotation_thread::unsubscribe_session_consumed_size_rotation(ltt_session
                _notification_channel.get(),
                lttng_trigger_get_const_condition(session.rotate_trigger));
        if (unsubscribe_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Failed to unsubscribe from consumed size condition used to control automatic size-based rotations: session_name=`{}` return_code={}",
                        session.name,
                        static_cast<int>(unsubscribe_status)));
@@ -935,7 +935,7 @@ void ls::rotation_thread::unsubscribe_session_consumed_size_rotation(ltt_session
                &_notification_thread_handle, session.rotate_trigger);
        if (unregister_status != LTTNG_OK) {
                LTTNG_THROW_CTL(
-                       fmt::format(
+                       lttng::format(
                                "Failed to unregister trigger for automatic size-based rotation: session_name{}",
                                session.name),
                        unregister_status);
index d8a01864b6245463db9901346ea79bc079bc5657..7e45f0a8a1fdbd4c0081d5b51ae7b816ca61345c 100644 (file)
@@ -222,7 +222,7 @@ private:
                                new_mappings->emplace_back(mapping);
                        } else {
                                /* Unsafe mapping, rename it and keep the rest of its attributes. */
-                               new_mappings->emplace_back(fmt::format("_{}", mapping.name),
+                               new_mappings->emplace_back(lttng::format("_{}", mapping.name),
                                                           mapping.range);
                        }
                }
@@ -248,7 +248,7 @@ private:
                        }
                }
 
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Failed to find mapping by range in enumeration while sanitizing a variant: target_mapping_range={}",
                        target_mapping_range));
        }
@@ -419,9 +419,9 @@ private:
                _description += "integer { ";
 
                /* Mandatory properties (no defaults). */
-               _description += fmt::format("size = {size}; align = {alignment};",
-                                           fmt::arg("size", type.size),
-                                           fmt::arg("alignment", type.alignment));
+               _description += lttng::format("size = {size}; align = {alignment};",
+                                             fmt::arg("size", type.size),
+                                             fmt::arg("alignment", type.alignment));
 
                /* Defaults to unsigned. */
                if (type.signedness_ == lst::integer_type::signedness::SIGNED) {
@@ -443,12 +443,12 @@ private:
                                base = 16;
                                break;
                        default:
-                               LTTNG_THROW_ERROR(fmt::format(
+                               LTTNG_THROW_ERROR(lttng::format(
                                        "Unexpected base encountered while serializing integer type to TSDL: base = {}",
                                        (int) type.base_));
                        }
 
-                       _description += fmt::format(" base = {};", base);
+                       _description += lttng::format(" base = {};", base);
                }
 
                /* Defaults to the trace's native byte order. */
@@ -456,7 +456,7 @@ private:
                        const auto byte_order_str =
                                type.byte_order == lst::byte_order::BIG_ENDIAN_ ? "be" : "le";
 
-                       _description += fmt::format(" byte_order = {};", byte_order_str);
+                       _description += lttng::format(" byte_order = {};", byte_order_str);
                }
 
                if (_current_integer_encoding_override) {
@@ -470,12 +470,12 @@ private:
                                encoding_str = "UTF8";
                                break;
                        default:
-                               LTTNG_THROW_ERROR(fmt::format(
+                               LTTNG_THROW_ERROR(lttng::format(
                                        "Unexpected encoding encountered while serializing integer type to TSDL: encoding = {}",
                                        (int) *_current_integer_encoding_override));
                        }
 
-                       _description += fmt::format(" encoding = {};", encoding_str);
+                       _description += lttng::format(" encoding = {};", encoding_str);
                        _current_integer_encoding_override.reset();
                }
 
@@ -489,7 +489,7 @@ private:
                            type.roles_.end()) {
                        LTTNG_ASSERT(_default_clock_class_name);
                        _description +=
-                               fmt::format(" map = clock.{}.value;", _default_clock_class_name);
+                               lttng::format(" map = clock.{}.value;", _default_clock_class_name);
                }
 
                _description += " }";
@@ -497,7 +497,7 @@ private:
 
        void visit(const lst::floating_point_type& type) final
        {
-               _description += fmt::format(
+               _description += lttng::format(
                        "floating_point {{ align = {alignment}; mant_dig = {mantissa_digits}; exp_dig = {exponent_digits};",
                        fmt::arg("alignment", type.alignment),
                        fmt::arg("mantissa_digits", type.mantissa_digits),
@@ -508,7 +508,7 @@ private:
                        const auto byte_order_str =
                                type.byte_order == lst::byte_order::BIG_ENDIAN_ ? "be" : "le";
 
-                       _description += fmt::format(" byte_order = {};", byte_order_str);
+                       _description += lttng::format(" byte_order = {};", byte_order_str);
                }
 
                _description += " }";
@@ -533,12 +533,12 @@ private:
 
                        _description.resize(_description.size() + mappings_indentation_level, '\t');
                        if (mapping.range.begin == mapping.range.end) {
-                               _description +=
-                                       fmt::format("\"{mapping_name}\" = {mapping_value}",
-                                                   fmt::arg("mapping_name", mapping.name),
-                                                   fmt::arg("mapping_value", mapping.range.begin));
+                               _description += lttng::format(
+                                       "\"{mapping_name}\" = {mapping_value}",
+                                       fmt::arg("mapping_name", mapping.name),
+                                       fmt::arg("mapping_value", mapping.range.begin));
                        } else {
-                               _description += fmt::format(
+                               _description += lttng::format(
                                        "\"{mapping_name}\" = {mapping_range_begin} ... {mapping_range_end}",
                                        fmt::arg("mapping_name", mapping.name),
                                        fmt::arg("mapping_range_begin", mapping.range.begin),
@@ -567,7 +567,7 @@ private:
        {
                if (type.alignment != 0) {
                        LTTNG_ASSERT(_current_field_name.size() > 0);
-                       _description += fmt::format(
+                       _description += lttng::format(
                                "struct {{ }} align({alignment}) {field_name}_padding;\n",
                                fmt::arg("alignment", type.alignment),
                                fmt::arg("field_name", _current_field_name.top()));
@@ -575,7 +575,7 @@ private:
                }
 
                type.element_type->accept(*this);
-               _type_suffixes.emplace(fmt::format("[{}]", type.length));
+               _type_suffixes.emplace(lttng::format("[{}]", type.length));
        }
 
        void visit(const lst::dynamic_length_array_type& type) final
@@ -588,7 +588,7 @@ private:
                         * would allow us to express alignment constraints.
                         */
                        LTTNG_ASSERT(_current_field_name.size() > 0);
-                       _description += fmt::format(
+                       _description += lttng::format(
                                "struct {{ }} align({alignment}) {field_name}_padding;\n",
                                fmt::arg("alignment", type.alignment),
                                fmt::arg("field_name", _current_field_name.top()));
@@ -596,7 +596,7 @@ private:
                }
 
                type.element_type->accept(*this);
-               _type_suffixes.emplace(fmt::format(
+               _type_suffixes.emplace(lttng::format(
                        "[{}]",
                        _bypass_identifier_escape ?
                                *(type.length_field_location.elements_.end() - 1) :
@@ -677,7 +677,7 @@ private:
        {
                if (type.alignment != 0) {
                        LTTNG_ASSERT(_current_field_name.size() > 0);
-                       _description += fmt::format(
+                       _description += lttng::format(
                                "struct {{ }} align({alignment}) {field_name}_padding;\n",
                                fmt::arg("alignment", type.alignment),
                                fmt::arg("field_name", _current_field_name.top()));
@@ -685,7 +685,7 @@ private:
                }
 
                _indentation_level++;
-               _description += fmt::format(
+               _description += lttng::format(
                        "variant <{}> {{\n",
                        _bypass_identifier_escape ?
                                *(type.selector_field_location.elements_.end() - 1) :
@@ -703,7 +703,7 @@ private:
                for (const auto& field : type.choices_) {
                        _description.resize(_description.size() + _indentation_level, '\t');
                        field.second->accept(*this);
-                       _description += fmt::format(" {};\n", field.first.name);
+                       _description += lttng::format(" {};\n", field.first.name);
                }
 
                _bypass_identifier_escape = previous_bypass_identifier_escape;
@@ -790,14 +790,13 @@ public:
 
        void visit(const lst::environment_field<int64_t>& field) override
        {
-               _environment += fmt::format("   {} = {};\n", field.name, field.value);
+               _environment += lttng::format(" {} = {};\n", field.name, field.value);
        }
 
        void visit(const lst::environment_field<const char *>& field) override
        {
-               _environment += fmt::format("   {} = \"{}\";\n",
-                                           field.name,
-                                           escape_tsdl_env_string_value(field.value));
+               _environment += lttng::format(
+                       "       {} = \"{}\";\n", field.name, escape_tsdl_env_string_value(field.value));
        }
 
        /* Only call once. */
@@ -835,7 +834,7 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::trace_class&
        trace_class.packet_header()->accept(packet_header_visitor);
 
        /* Declare type aliases, trace class, and packet header. */
-       auto trace_class_tsdl = fmt::format(
+       auto trace_class_tsdl = lttng::format(
                "/* CTF {ctf_major}.{ctf_minor} */\n\n"
                "trace {{\n"
                "       major = {ctf_major};\n"
@@ -869,24 +868,24 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::trace_class&
 void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::clock_class& clock_class)
 {
        auto uuid_str = clock_class.uuid ?
-               fmt::format("   uuid = \"{}\";\n", lttng::utils::uuid_to_str(*clock_class.uuid)) :
+               lttng::format(" uuid = \"{}\";\n", lttng::utils::uuid_to_str(*clock_class.uuid)) :
                "";
 
        /* Assumes a single clock that maps to specific stream class fields/roles. */
-       auto clock_class_str = fmt::format("clock {{\n"
-                                          "    name = \"{name}\";\n"
-                                          /* Optional uuid. */
-                                          "{uuid}"
-                                          "    description = \"{description}\";\n"
-                                          "    freq = {frequency};\n"
-                                          "    offset = {offset};\n"
-                                          "}};\n"
-                                          "\n",
-                                          fmt::arg("name", clock_class.name),
-                                          fmt::arg("uuid", uuid_str),
-                                          fmt::arg("description", clock_class.description),
-                                          fmt::arg("frequency", clock_class.frequency),
-                                          fmt::arg("offset", clock_class.offset));
+       auto clock_class_str = lttng::format("clock {{\n"
+                                            "  name = \"{name}\";\n"
+                                            /* Optional uuid. */
+                                            "{uuid}"
+                                            "  description = \"{description}\";\n"
+                                            "  freq = {frequency};\n"
+                                            "  offset = {offset};\n"
+                                            "}};\n"
+                                            "\n",
+                                            fmt::arg("name", clock_class.name),
+                                            fmt::arg("uuid", uuid_str),
+                                            fmt::arg("description", clock_class.description),
+                                            fmt::arg("frequency", clock_class.frequency),
+                                            fmt::arg("offset", clock_class.offset));
 
        append_metadata_fragment(clock_class_str);
 }
@@ -897,9 +896,9 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class
        const auto clear_stream_class_on_exit =
                lttng::make_scope_exit([this]() noexcept { _current_stream_class = nullptr; });
 
-       auto stream_class_str = fmt::format("stream {{\n"
-                                           "   id = {};\n",
-                                           stream_class.id);
+       auto stream_class_str = lttng::format("stream {{\n"
+                                             " id = {};\n",
+                                             stream_class.id);
        variant_tsdl_keyword_sanitizer variant_sanitizer(
                _sanitized_types_overrides,
                [this](const lttng::sessiond::trace::field_location& location) -> const lst::type& {
@@ -915,8 +914,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class
 
                event_header->accept(variant_sanitizer);
                event_header->accept(event_header_visitor);
-               stream_class_str += fmt::format("       event.header := {};\n",
-                                               event_header_visitor.move_description());
+               stream_class_str += lttng::format("     event.header := {};\n",
+                                                 event_header_visitor.move_description());
        }
 
        const auto *packet_context = stream_class.packet_context();
@@ -928,8 +927,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class
 
                packet_context->accept(variant_sanitizer);
                packet_context->accept(packet_context_visitor);
-               stream_class_str += fmt::format("       packet.context := {};\n",
-                                               packet_context_visitor.move_description());
+               stream_class_str += lttng::format("     packet.context := {};\n",
+                                                 packet_context_visitor.move_description());
        }
 
        const auto *event_context = stream_class.event_context();
@@ -940,8 +939,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class
 
                event_context->accept(variant_sanitizer);
                event_context->accept(event_context_visitor);
-               stream_class_str += fmt::format("       event.context := {};\n",
-                                               event_context_visitor.move_description());
+               stream_class_str += lttng::format("     event.context := {};\n",
+                                                 event_context_visitor.move_description());
        }
 
        stream_class_str += "};\n\n";
@@ -955,19 +954,20 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::event_class&
        const auto clear_event_class_on_exit =
                lttng::make_scope_exit([this]() noexcept { _current_event_class = nullptr; });
 
-       auto event_class_str = fmt::format("event {{\n"
-                                          "    name = \"{name}\";\n"
-                                          "    id = {id};\n"
-                                          "    stream_id = {stream_class_id};\n"
-                                          "    loglevel = {log_level};\n",
-                                          fmt::arg("name", event_class.name),
-                                          fmt::arg("id", event_class.id),
-                                          fmt::arg("stream_class_id", event_class.stream_class_id),
-                                          fmt::arg("log_level", event_class.log_level));
+       auto event_class_str =
+               lttng::format("event {{\n"
+                             " name = \"{name}\";\n"
+                             " id = {id};\n"
+                             " stream_id = {stream_class_id};\n"
+                             " loglevel = {log_level};\n",
+                             fmt::arg("name", event_class.name),
+                             fmt::arg("id", event_class.id),
+                             fmt::arg("stream_class_id", event_class.stream_class_id),
+                             fmt::arg("log_level", event_class.log_level));
 
        if (event_class.model_emf_uri) {
                event_class_str +=
-                       fmt::format("   model.emf.uri = \"{}\";\n", *event_class.model_emf_uri);
+                       lttng::format(" model.emf.uri = \"{}\";\n", *event_class.model_emf_uri);
        }
 
        tsdl_field_visitor payload_visitor{ _trace_abi, 1, _sanitized_types_overrides };
@@ -981,7 +981,7 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::event_class&
        event_class.payload->accept(payload_visitor);
 
        event_class_str +=
-               fmt::format("   fields := {};\n}};\n\n", payload_visitor.move_description());
+               lttng::format(" fields := {};\n}};\n\n", payload_visitor.move_description());
 
        append_metadata_fragment(event_class_str);
 }
@@ -1033,7 +1033,7 @@ lookup_type_from_root_type(const lttng::sessiond::trace::type& root_type,
                 * safely.
                 */
                if (!struct_type) {
-                       LTTNG_THROW_ERROR(fmt::format(
+                       LTTNG_THROW_ERROR(lttng::format(
                                "Encountered a type that is not a structure while traversing field location: field-location=`{}`",
                                field_location));
                }
@@ -1046,7 +1046,7 @@ lookup_type_from_root_type(const lttng::sessiond::trace::type& root_type,
                                     });
 
                if (field_found_it == struct_type->fields_.cend()) {
-                       LTTNG_THROW_ERROR(fmt::format(
+                       LTTNG_THROW_ERROR(lttng::format(
                                "Failed to find field using field location: field-name:=`{field_name}`, field-location=`{field_location}`",
                                fmt::arg("field_location", field_location),
                                fmt::arg("field_name", location_element)));
index b9091424bb274b6b80a837ee519b7bf0e8dd6689..d7b1275b0814571eece6f951fda7bd23d2247512 100644 (file)
@@ -6842,7 +6842,7 @@ static int add_enum_ust_registry(int sock,
                application_reply_code = 0;
        } catch (const std::exception& ex) {
                ERR("%s: %s",
-                   fmt::format(
+                   lttng::format(
                            "Failed to create or find enumeration provided by application: app = {}, enumeration name = {}",
                            *app,
                            name)
index 10736611cfff317ef6d365a10386975425901fcd..b51ba7bfc2c7e55ea4749b0e2d41807a7a33deed 100644 (file)
@@ -90,7 +90,7 @@ ust_ctl_encoding_to_string_field_encoding(UstCtlEncodingType encoding)
 
        const auto encoding_it = encoding_conversion_map.find(encoding);
        if (encoding_it == encoding_conversion_map.end()) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown lttng_ust_ctl_string_encodings value `{}` encountered when decoding integer field",
                        encoding));
        }
@@ -109,7 +109,7 @@ enum lst::integer_type::base ust_ctl_base_to_integer_field_base(UstCtlBaseType b
 
        const auto base_it = base_conversion_map.find(base);
        if (base_it == base_conversion_map.end()) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown integer base value `{}` encountered when decoding integer field",
                        base));
        }
@@ -125,7 +125,7 @@ create_integer_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                        lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -154,7 +154,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren
                                               lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -171,7 +171,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren
                        current->type.u._float.exp_dig,
                        current->type.u._float.mant_dig);
        } catch (lttng::invalid_argument_error& ex) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Invalid floating point attribute in {}: {}", typeid(*current), ex.what()));
        }
 }
@@ -184,7 +184,7 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                            lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -198,15 +198,15 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                /* Nestable enumeration fields are followed by their container type. */
                ++current;
                if (current >= end) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Array of {} is too short to contain nestable enumeration's container",
                                typeid(*current)));
                }
 
                if (current->type.atype != lttng_ust_ctl_atype_integer) {
-                       LTTNG_THROW_PROTOCOL_ERROR(
-                               fmt::format("Invalid type of nestable enum container: type id = {}",
-                                           current->type.atype));
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
+                               "Invalid type of nestable enum container: type id = {}",
+                               current->type.atype));
                }
 
                enum_container_uctl_type = &current->type.u.integer;
@@ -259,7 +259,7 @@ create_string_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                       lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -301,7 +301,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                      lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -315,7 +315,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
 
        const auto& element_uctl_type = array_uctl_field.type.u.legacy.array.elem_type;
        if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy array element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        element_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
@@ -337,7 +337,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -363,7 +363,7 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -400,7 +400,7 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -429,7 +429,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -439,14 +439,14 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
        const auto sequence_alignment = 0U;
 
        if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy sequence element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        element_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
        }
 
        if (length_uctl_type.atype != lttng_ust_ctl_atype_integer) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unexpected legacy sequence length field type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})",
                        length_uctl_type.atype,
                        lttng_ust_ctl_atype_integer));
@@ -460,7 +460,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
                        element_uctl_type.u.basic.integer.encoding);
        }
 
-       auto length_field_name = fmt::format("_{}_length", sequence_uctl_field.name);
+       auto length_field_name = lttng::format("_{}_length", sequence_uctl_field.name);
        auto element_type =
                create_integer_type_from_ust_ctl_basic_type(element_uctl_type, session_attributes);
        auto length_type =
@@ -484,7 +484,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -510,7 +510,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -567,7 +567,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields(
                        static_cast<const lst::integer_type&>(*element_type).size;
 
                if (integer_element_size != 8) {
-                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                "Unexpected array element type: integer has encoding but size is not 8: size = {}",
                                integer_element_size));
                }
@@ -590,7 +590,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                           lsu::ctl_field_quirks quirks __attribute__((unused)))
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -607,7 +607,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
        }
 
        if (field_count != 0) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Only empty structures are supported by LTTng-UST: nr_fields = {}",
                        field_count));
        }
@@ -673,7 +673,7 @@ create_typed_variant_choices(const lttng_ust_ctl_field *current,
                                        });
 
                                if (mapping_it == typed_enumeration.mappings_->end()) {
-                                       LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+                                       LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                                                "Invalid variant choice: `{}` does not match any mapping in `{}` enumeration",
                                                field->name,
                                                selector_field.name));
@@ -703,7 +703,7 @@ lst::type::cuptr create_variant_field_from_ust_ctl_fields(
        lsu::ctl_field_quirks quirks)
 {
        if (current >= end) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "End of {} array reached unexpectedly during decoding", typeid(*current)));
        }
 
@@ -855,11 +855,11 @@ create_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
                                                                quirks);
        default:
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Unknown {} value `{}` encountered while converting {} to {}",
-                                   typeid(current->type.atype),
-                                   current->type.atype,
-                                   typeid(*current),
-                                   typeid(lst::type::cuptr::element_type)));
+                       lttng::format("Unknown {} value `{}` encountered while converting {} to {}",
+                                     typeid(current->type.atype),
+                                     current->type.atype,
+                                     typeid(*current),
+                                     typeid(lst::type::cuptr::element_type)));
        }
 }
 
@@ -877,7 +877,7 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current,
 
        if (lttng_strnlen(current->name, sizeof(current->name)) == sizeof(current->name)) {
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Name of {} is not null-terminated", typeid(*current)));
+                       lttng::format("Name of {} is not null-terminated", typeid(*current)));
        }
 
        publish_field(lttng::make_unique<lst::field>(
@@ -897,7 +897,7 @@ std::vector<lst::field::cuptr>::iterator
 lookup_field_in_vector(std::vector<lst::field::cuptr>& fields, const lst::field_location& location)
 {
        if (location.elements_.size() != 1) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Unexpected field location received during field look-up: location = {}",
                        location));
        }
@@ -916,7 +916,7 @@ lookup_field_in_vector(std::vector<lst::field::cuptr>& fields, const lst::field_
 
        if (field_it == fields.end()) {
                LTTNG_THROW_PROTOCOL_ERROR(
-                       fmt::format("Failed to look-up field: location = {}", location));
+                       lttng::format("Failed to look-up field: location = {}", location));
        }
 
        return field_it;
index 03532cd09e65dfdd9fc4105a02ec1c9e6ecc9124..f4c8f226e09f104b33b7142a16d1b59fe8878425 100644 (file)
@@ -388,14 +388,14 @@ void lsu::registry_channel::add_event(int session_objd,
         * external party, don't assert and simply validate values.
         */
        if (session_objd < 0) {
-               LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+               LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                        "Invalid session object descriptor provided by application: session descriptor = {}, app = {}",
                        session_objd,
                        app));
        }
 
        if (channel_objd < 0) {
-               LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+               LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                        "Invalid channel object descriptor provided by application: channel descriptor = {}, app = {}",
                        channel_objd,
                        app));
@@ -403,7 +403,7 @@ void lsu::registry_channel::add_event(int session_objd,
 
        /* Check if we've reached the maximum possible id. */
        if (is_max_event_id(_next_event_id)) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Failed to allocate new event id (id would overflow): app = {}", app));
        }
 
@@ -418,7 +418,7 @@ void lsu::registry_channel::add_event(int session_objd,
                                        loglevel_value,
                                        std::move(model_emf_uri)));
 
-       DBG3("%s", fmt::format("UST registry creating event: event = {}", *event).c_str());
+       DBG3("%s", lttng::format("UST registry creating event: event = {}", *event).c_str());
 
        /*
         * This is an add unique with a custom match function for event. The node
@@ -439,7 +439,7 @@ void lsu::registry_channel::add_event(int session_objd,
                                nptr, &lttng::sessiond::ust::registry_event::_node);
                        event_id = existing_event->id;
                } else {
-                       LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+                       LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                                "UST registry create event add unique failed for event: event = {}",
                                *event));
                }
index c75fc38481245894cdf251fabf18286d26ee1562..518108cbde4ce97eede2d209c841a35450c56e7c 100644 (file)
@@ -240,7 +240,7 @@ lsu::registry_session::registry_session(const struct lst::abi& in_abi,
        lst::trace_class(in_abi, generate_uuid_or_throw()),
        _root_shm_path{ root_shm_path ? root_shm_path : "" },
        _shm_path{ shm_path ? shm_path : "" },
-       _metadata_path{ _shm_path.size() > 0 ? fmt::format("{}/metadata", _shm_path) :
+       _metadata_path{ _shm_path.size() > 0 ? lttng::format("{}/metadata", _shm_path) :
                                               std::string("") },
        _uid{ euid },
        _gid{ egid },
@@ -268,7 +268,7 @@ lsu::registry_session::registry_session(const struct lst::abi& in_abi,
                                            egid);
                if (ret < 0) {
                        LTTNG_THROW_POSIX(
-                               fmt::format(
+                               lttng::format(
                                        "Failed to open metadata file during registry session creation: path = {}",
                                        _metadata_path),
                                errno);
@@ -451,7 +451,7 @@ void lsu::registry_session::add_channel(uint64_t key)
         * the metadata can be dumped for that event.
         */
        if (is_max_channel_id(_used_channel_id)) {
-               LTTNG_THROW_ERROR(fmt::format(
+               LTTNG_THROW_ERROR(lttng::format(
                        "Failed to allocate unique id for channel under session while adding channel"));
        }
 
@@ -496,8 +496,8 @@ lttng::sessiond::ust::registry_channel& lsu::registry_session::channel(uint64_t
        lttng_ht_lookup(_channels.get(), &channel_key, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (!node) {
-               LTTNG_THROW_INVALID_ARGUMENT_ERROR(
-                       fmt::format("Invalid channel key provided: channel key = {}", channel_key));
+               LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
+                       "Invalid channel key provided: channel key = {}", channel_key));
        }
 
        DIAGNOSTIC_PUSH
@@ -722,7 +722,7 @@ lsu::registry_session::enumeration(const char *enum_name, uint64_t enum_id) cons
                        &iter.iter);
        node = lttng_ht_iter_get_node_str(&iter);
        if (!node) {
-               LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+               LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown enumeration referenced by application event field: enum name = `{}`, enum id = {}",
                        enum_name,
                        enum_id));
@@ -795,12 +795,12 @@ void lsu::registry_session::create_or_find_enum(int session_objd,
         * external party, don't assert and simply validate values.
         */
        if (session_objd < 0) {
-               LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+               LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                        "Invalid parameters used to create or look-up enumeration from registry session: session_objd = {}",
                        session_objd));
        }
        if (nr_entries == 0) {
-               LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+               LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                        "Invalid parameters used to create or look-up enumeration from registry session: nr_entries = {}",
                        nr_entries));
        }
index 019906a208d1af7bc0673413f045d783bf3a2ae4..0258e31e858ced1d61dfb76a85d916f6932d203c 100644 (file)
@@ -74,7 +74,7 @@ cmd_error_code destroy_session(const lttng_session& session)
 
        ret = lttng_stop_tracing_no_wait(session.name);
        if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
-               LTTNG_THROW_CTL(fmt::format("Failed to stop session `{}`", session.name),
+               LTTNG_THROW_CTL(lttng::format("Failed to stop session `{}`", session.name),
                                static_cast<lttng_error_code>(-ret));
        }
 
@@ -134,7 +134,8 @@ cmd_error_code destroy_session(const lttng_session& session)
                auto ctl_ret_code =
                        lttng_destroy_session_ext(session.name, &raw_destruction_handle);
                if (ctl_ret_code != LTTNG_OK) {
-                       LTTNG_THROW_CTL(fmt::format("Failed to destroy session `{}`", session.name),
+                       LTTNG_THROW_CTL(lttng::format("Failed to destroy session `{}`",
+                                                     session.name),
                                        ctl_ret_code);
                }
 
@@ -184,7 +185,8 @@ cmd_error_code destroy_session(const lttng_session& session)
                }
 
                if (ctl_ret_code != LTTNG_OK) {
-                       LTTNG_THROW_CTL(fmt::format("Failed to destroy session `{}`", session.name),
+                       LTTNG_THROW_CTL(lttng::format("Failed to destroy session `{}`",
+                                                     session.name),
                                        ctl_ret_code);
                }
 
index 29cff53c2fb1cc0cd3457cde5066159b0e6ba21f..f78d3e708aa80c0fd05865cd36ef965ada3790e8 100644 (file)
@@ -89,7 +89,7 @@ cmd_error_code start_tracing(const char *session_name)
 
        const int ret = lttng_start_tracing(session_name);
        if (ret < 0) {
-               LTTNG_THROW_CTL(fmt::format("Failed to start session `{}`", session_name),
+               LTTNG_THROW_CTL(lttng::format("Failed to start session `{}`", session_name),
                                static_cast<lttng_error_code>(-ret));
        }
 
index 8b33bd7f4af5e7dc46c2c5b231432c059a0befe2..af42d98db1f291f12d615976b29d3646cd573316 100644 (file)
@@ -91,7 +91,7 @@ cmd_error_code stop_tracing(const char *session_name)
 
        ret = lttng_stop_tracing_no_wait(session_name);
        if (ret < 0) {
-               LTTNG_THROW_CTL(fmt::format("Failed to start session `{}`", session_name),
+               LTTNG_THROW_CTL(lttng::format("Failed to start session `{}`", session_name),
                                static_cast<lttng_error_code>(-ret));
        }
 
index c2c59f89da06f07595d5c7cd262dfbc3fcbdde35..0ed96d44ac51f6126c92f8eb77ba1eaa0ddda047 100644 (file)
@@ -144,7 +144,7 @@ public:
        operator[](std::size_t index) const
        {
                if (index >= ContainerOperations::size(_container)) {
-                       LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+                       LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                                "Out of bound access through random_access_container_wrapper: index={}, size={}",
                                index,
                                size()));
index 5935cf1515228cfafa3318bd52b9fa740c032b98..23d840c2daafcd3870ba4445708921c1ea3b93ad 100644 (file)
@@ -266,7 +266,7 @@ namespace details {
 #define DBG_FMT(format_str, args...)                                                              \
        do {                                                                                      \
                try {                                                                             \
-                       DBG("%s", fmt::format(format_str, ##args).c_str());                       \
+                       DBG("%s", lttng::format(format_str, ##args).c_str());                     \
                } catch (const std::exception& _formatting_exception) {                           \
                        lttng::logging::details::die_formatting_exception(format_str,             \
                                                                          _formatting_exception); \
@@ -276,7 +276,7 @@ namespace details {
 #define WARN_FMT(format_str, args...)                                                             \
        do {                                                                                      \
                try {                                                                             \
-                       WARN("%s", fmt::format(format_str, ##args).c_str());                      \
+                       WARN("%s", lttng::format(format_str, ##args).c_str());                    \
                } catch (const std::exception& _formatting_exception) {                           \
                        lttng::logging::details::die_formatting_exception(format_str,             \
                                                                          _formatting_exception); \
@@ -286,7 +286,7 @@ namespace details {
 #define ERR_FMT(format_str, args...)                                                              \
        do {                                                                                      \
                try {                                                                             \
-                       ERR("%s", fmt::format(format_str, ##args).c_str());                       \
+                       ERR("%s", lttng::format(format_str, ##args).c_str());                     \
                } catch (const std::exception& _formatting_exception) {                           \
                        lttng::logging::details::die_formatting_exception(format_str,             \
                                                                          _formatting_exception); \
index 6858526825b6af3e278655eee3053f1cf10209dd..cb12a51ab4f3c07928b23336a5e332d9edb376bc 100644 (file)
@@ -36,7 +36,7 @@ void lttng::eventfd::increment(std::uint64_t value)
        try {
                write(&value, sizeof(value));
        } catch (const std::exception& e) {
-               LTTNG_THROW_ERROR(fmt::format("Failed to increment eventfd: {}", e.what()));
+               LTTNG_THROW_ERROR(lttng::format("Failed to increment eventfd: {}", e.what()));
        }
 }
 
@@ -47,7 +47,7 @@ std::uint64_t lttng::eventfd::decrement()
        try {
                read(&value, sizeof(value));
        } catch (const std::exception& e) {
-               LTTNG_THROW_ERROR(fmt::format("Failed to decrement eventfd: {}", e.what()));
+               LTTNG_THROW_ERROR(lttng::format("Failed to decrement eventfd: {}", e.what()));
        }
 
        return value;
index 6f6a6be24dc6fdbfbcffab9f63633cb6e7314d1e..93d7b699f5961eee8cd26e5ffe05b182acb07eb3 100644 (file)
@@ -77,7 +77,7 @@ void lttng::file_descriptor::write(const void *buffer, std::size_t size)
                std::numeric_limits<lttng_write_return_type>::max();
 
        if (size > max_supported_write_size) {
-               LTTNG_THROW_UNSUPPORTED_ERROR(fmt::format(
+               LTTNG_THROW_UNSUPPORTED_ERROR(lttng::format(
                        "Write size exceeds the maximal supported value of lttng_write: write_size={}, maximal_write_size={}",
                        size,
                        max_supported_write_size));
@@ -85,7 +85,7 @@ void lttng::file_descriptor::write(const void *buffer, std::size_t size)
 
        const auto write_ret = lttng_write(fd(), buffer, size);
        if (write_ret < 0 || static_cast<std::size_t>(write_ret) != size) {
-               LTTNG_THROW_POSIX(fmt::format("Failed to write to file descriptor: fd={}", fd()),
+               LTTNG_THROW_POSIX(lttng::format("Failed to write to file descriptor: fd={}", fd()),
                                  errno);
        }
 }
@@ -101,7 +101,7 @@ void lttng::file_descriptor::read(void *buffer, std::size_t size)
        constexpr auto max_supported_read_size = std::numeric_limits<lttng_read_return_type>::max();
 
        if (size > max_supported_read_size) {
-               LTTNG_THROW_UNSUPPORTED_ERROR(fmt::format(
+               LTTNG_THROW_UNSUPPORTED_ERROR(lttng::format(
                        "Read size exceeds the maximal supported value of lttng_read: read_size={}, maximal_read_size={}",
                        size,
                        max_supported_read_size));
@@ -109,7 +109,7 @@ void lttng::file_descriptor::read(void *buffer, std::size_t size)
 
        const auto read_ret = lttng_read(fd(), buffer, size);
        if (read_ret < 0 || static_cast<std::size_t>(read_ret) != size) {
-               LTTNG_THROW_POSIX(fmt::format("Failed to read from file descriptor: fd={}", fd()),
+               LTTNG_THROW_POSIX(lttng::format("Failed to read from file descriptor: fd={}", fd()),
                                  errno);
        }
 }
index 389bc596ad85787c7f00aa7506532f56898551cf..c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <cxxabi.h>
 #include <string>
+#include <utility>
 
 DIAGNOSTIC_PUSH
 DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
@@ -42,4 +43,16 @@ struct formatter<std::type_info> : formatter<std::string> {
 };
 } /* namespace fmt */
 
+namespace lttng {
+template <typename... FormattingArguments>
+std::string format(FormattingArguments&&...args)
+{
+       try {
+               return fmt::format(std::forward<FormattingArguments>(args)...);
+       } catch (const fmt::format_error& ex) {
+               return std::string("Failed to format string: ") += ex.what();
+       }
+}
+} /* namespace lttng */
+
 #endif /* LTTNG_FORMAT_H */
index 26f51d3a4a0a674e19c3721b69ee5ad23eefa2b0..ba9d937ba32b95f43f877348ac0f358ea9c7e071 100644 (file)
@@ -67,8 +67,8 @@ void getrandom_nonblock(char *out_data, std::size_t size)
 
        if (ret < 0) {
                LTTNG_THROW_POSIX(
-                       fmt::format("Failed to get true random data using getrandom(): size={}",
-                                   size),
+                       lttng::format("Failed to get true random data using getrandom(): size={}",
+                                     size),
                        errno);
        }
 }
@@ -152,7 +152,7 @@ lttng::random::seed_t produce_random_seed_from_urandom()
        try {
                urandom.read(&seed, sizeof(seed));
        } catch (const std::exception& e) {
-               LTTNG_THROW_RANDOM_PRODUCTION_ERROR(fmt::format(
+               LTTNG_THROW_RANDOM_PRODUCTION_ERROR(lttng::format(
                        "Failed to read from `/dev/urandom`: size={}: {}", sizeof(seed), e.what()));
        }
 
@@ -183,7 +183,7 @@ lttng::random::seed_t lttng::random::produce_best_effort_random_seed()
                return lttng::random::produce_true_random_seed();
        } catch (const std::exception& e) {
                WARN("%s",
-                    fmt::format(
+                    lttng::format(
                             "Failed to produce a random seed using getrandom(), falling back to pseudo-random device seed generation which will block until its pool is initialized: {}",
                             e.what())
                             .c_str());
@@ -197,8 +197,8 @@ lttng::random::seed_t lttng::random::produce_best_effort_random_seed()
                produce_random_seed_from_urandom();
        } catch (const std::exception& e) {
                WARN("%s",
-                    fmt::format("Failed to produce a random seed from the urandom device: {}",
-                                e.what())
+                    lttng::format("Failed to produce a random seed from the urandom device: {}",
+                                  e.what())
                             .c_str());
        }
 
This page took 0.050286 seconds and 4 git commands to generate.