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
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();
}
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"]));
}
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));
}
}
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));
}
return;
}
- LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+ LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
"Invalid exponent/mantissa values provided while creating {}", typeid(*this)));
}
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 */
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 ||
if (lttng_read(fd, &buf, 1) != 1) {
LTTNG_THROW_POSIX(
- fmt::format(
+ lttng::format(
"Failed to read from wakeup pipe: fd={}",
fd),
errno);
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));
}
&_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),
_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)));
&_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);
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);
}
}
}
}
- 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));
}
_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) {
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. */
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) {
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();
}
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 += " }";
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),
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 += " }";
_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),
{
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()));
}
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
* 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()));
}
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) :
{
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()));
}
_indentation_level++;
- _description += fmt::format(
+ _description += lttng::format(
"variant <{}> {{\n",
_bypass_identifier_escape ?
*(type.selector_field_location.elements_.end() - 1) :
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;
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. */
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"
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);
}
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& {
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();
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();
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";
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 };
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);
}
* 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));
}
});
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)));
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)
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));
}
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));
}
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)));
}
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)));
}
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()));
}
}
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)));
}
/* 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 = ¤t->type.u.integer;
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)));
}
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)));
}
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));
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));
}
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)));
}
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));
}
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)));
}
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));
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 =
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));
}
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)));
}
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));
}
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)));
}
}
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));
}
});
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));
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)));
}
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)));
}
}
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>(
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));
}
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;
* 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));
/* 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));
}
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
nptr, <tng::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));
}
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 },
egid);
if (ret < 0) {
LTTNG_THROW_POSIX(
- fmt::format(
+ lttng::format(
"Failed to open metadata file during registry session creation: path = {}",
_metadata_path),
errno);
* 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"));
}
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
&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));
* 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));
}
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));
}
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);
}
}
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);
}
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));
}
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));
}
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()));
#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); \
#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); \
#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); \
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()));
}
}
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;
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));
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);
}
}
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));
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);
}
}
#include <cxxabi.h>
#include <string>
+#include <utility>
DIAGNOSTIC_PUSH
DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
};
} /* 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 */
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);
}
}
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()));
}
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());
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());
}