mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
AK: Add support for "debug only" formatters
These are formatters that can only be used with debug print functions, such as dbgln(). Currently this is limited to Formatter<ErrorOr<T>>. With this you can still debug log ErrorOr values (good for debugging), but trying to use them in any String::formatted() call will fail (which prevents .to_string() errors with the new failable strings being ignored). You make a formatter debug only by adding a constexpr method like: static constexpr bool is_debug_only() { return true; }
This commit is contained in:
parent
1388375310
commit
9a120d7243
10 changed files with 36 additions and 17 deletions
|
@ -48,7 +48,7 @@ void dmesgln_pci(Device const& device, AK::CheckedFormatString<Parameters...>&&
|
|||
return;
|
||||
if (builder.try_append(fmt.view()).is_error())
|
||||
return;
|
||||
AK::VariadicFormatParams variadic_format_params { device.device_name(), device.pci_address(), parameters... };
|
||||
AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::Yes, StringView, Address, Parameters...> variadic_format_params { device.device_name(), device.pci_address(), parameters... };
|
||||
vdmesgln(builder.string_view(), variadic_format_params);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
{
|
||||
// FIXME: This really not ideal, but vformat expects StringBuilder.
|
||||
StringBuilder builder;
|
||||
AK::VariadicFormatParams variadic_format_params { parameters... };
|
||||
AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
|
||||
TRY(vformat(builder, fmtstr.view(), variadic_format_params));
|
||||
return append_bytes(builder.string_view().bytes());
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
template<typename... Parameters>
|
||||
[[nodiscard]] static ErrorOr<NonnullOwnPtr<KString>> formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||
{
|
||||
AK::VariadicFormatParams variadic_format_parameters { parameters... };
|
||||
AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
|
||||
return vformatted(fmtstr.view(), variadic_format_parameters);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue