ladybird
ladybird copied to clipboard
AK: Rework windows error types to store the code
This commit makes windows errors store the code instead of being a formatted string literat. This will allow comparing against the error, and checkign what it is. The formatting is now done in the formatter, and moved to an implementation file to avoid polluting headers with windows.h.
what happened in this CI? I see the error but I don't understand why it happens on only these two builds, or why it happens tbh.
This is a difference in behavior in clang and gcc. Gcc is unable to tell that all control flow paths are handled. Adding a default case fixes it, but breaks -Wswitch. Adding unreachable fixes it. repro: https://godbolt.org/z/1n4WPna4r
Compare view is useless due to rebase, but everything looks fine. I'll compile locally and check.
This is the reason that I did that weird thing with the format reference:
D:\lib\ladybird\AK\Format.cpp(1102,39): error: call to non-static member function without an object argument
1102 | return Formatter<StringView>::format(builder, string->view());
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
D:\lib\ladybird\AK\Format.cpp(1116,41): error: call to non-static member function without an object argument
1116 | return Formatter<FormatString>::format(builder, "Error {:08x} when formatting code {:08x}"sv, format_error, code);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
D:\lib\ladybird\AK\Format.cpp(1121,35): error: call to non-static member function without an object argument
1121 | return Formatter<StringView>::format(builder, string_in_map.view());
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
3 errors generated.
It simply doesn't compile this way. Edit: fixed typo, in code, makes the error cleaner.
Doing this solves the issue, but exposes it in a header.
diff --git a/AK/Format.cpp b/AK/Format.cpp
index 61508cb5cd..6526cb0f9f 100644
--- a/AK/Format.cpp
+++ b/AK/Format.cpp
@@ -1092,7 +1092,7 @@ void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool ne
}
}
#if defined(AK_OS_WINDOWS)
-static ErrorOr<void> format_windows_error(FormatBuilder& builder, Error const& error)
+ErrorOr<void> Formatter<Error>::format_windows_error(FormatBuilder& builder, Error const& error)
{
thread_local HashMap<u32, ByteString> windows_errors;
@@ -1113,7 +1113,7 @@ static ErrorOr<void> format_windows_error(FormatBuilder& builder, Error const& e
nullptr);
if (size == 0) {
auto format_error = GetLastError();
- return Formatter::<FormatString>::format(builder, "Error {:08x} when formatting code {:08x}"sv, format_error, code);
+ return Formatter<FormatString>::format(builder, "Error {:08x} when formatting code {:08x}"sv, format_error, code);
}
auto& string_in_map = windows_errors.ensure(code, [message, size] { return ByteString { message, size }; });
diff --git a/AK/Format.h b/AK/Format.h
index d7514fad44..ff36e2d4eb 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -738,6 +738,7 @@ struct Formatter<FormatString> : Formatter<StringView> {
template<>
struct Formatter<Error> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, Error const& error);
+ ErrorOr<void> format_windows_error(FormatBuilder& builder, Error const& error);
};
template<typename T, typename ErrorType>
Should I push it or is there another way around it?