summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-12 19:16:13 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-02-13 02:36:35 +0200
commit4c451422c35b3c2044d3b005a7af32d18ce9b194 (patch)
tree4f2fb5a471bd36c4747845a9466fcaffce490ff0
parentd4f08b3096aad1be8f162570e8c33376318110e3 (diff)
downloadserenity-4c451422c35b3c2044d3b005a7af32d18ce9b194.zip
gml-format+Playground: Print GML parsing error on formatting failure
-rw-r--r--Userland/DevTools/Playground/main.cpp8
-rw-r--r--Userland/Libraries/LibGUI/GML/Formatter.h7
-rw-r--r--Userland/Utilities/gml-format.cpp7
3 files changed, 10 insertions, 12 deletions
diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp
index bf688c9b3a..a32328f66f 100644
--- a/Userland/DevTools/Playground/main.cpp
+++ b/Userland/DevTools/Playground/main.cpp
@@ -215,13 +215,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto edit_menu = TRY(window->try_add_menu("&Edit"));
TRY(edit_menu->try_add_action(GUI::Action::create("&Format GML", { Mod_Ctrl | Mod_Shift, Key_I }, [&](auto&) {
- auto formatted_gml = GUI::GML::format_gml(editor->text());
- if (!formatted_gml.is_null()) {
- editor->set_text(formatted_gml);
+ auto formatted_gml_or_error = GUI::GML::format_gml(editor->text());
+ if (!formatted_gml_or_error.is_error()) {
+ editor->set_text(formatted_gml_or_error.release_value());
} else {
GUI::MessageBox::show(
window,
- "GML could not be formatted, please check the debug console for parsing errors.",
+ String::formatted("GML could not be formatted: {}", formatted_gml_or_error.error()),
"Error",
GUI::MessageBox::Type::Error);
}
diff --git a/Userland/Libraries/LibGUI/GML/Formatter.h b/Userland/Libraries/LibGUI/GML/Formatter.h
index c5d7cfe809..e4618689c3 100644
--- a/Userland/Libraries/LibGUI/GML/Formatter.h
+++ b/Userland/Libraries/LibGUI/GML/Formatter.h
@@ -13,12 +13,9 @@
namespace GUI::GML {
-inline String format_gml(StringView string)
+inline ErrorOr<String> format_gml(StringView string)
{
- auto ast = parse_gml(string);
- if (ast.is_error())
- return {};
- return ast.value()->to_string();
+ return TRY(parse_gml(string))->to_string();
}
}
diff --git a/Userland/Utilities/gml-format.cpp b/Userland/Utilities/gml-format.cpp
index 5a2812b5df..cd0d441243 100644
--- a/Userland/Utilities/gml-format.cpp
+++ b/Userland/Utilities/gml-format.cpp
@@ -23,11 +23,12 @@ ErrorOr<bool> format_file(StringView path, bool inplace)
file = TRY(Core::File::open(path, open_mode));
}
auto contents = file->read_all();
- auto formatted_gml = GUI::GML::format_gml(contents);
- if (formatted_gml.is_null()) {
- warnln("Failed to parse GML!");
+ auto formatted_gml_or_error = GUI::GML::format_gml(contents);
+ if (formatted_gml_or_error.is_error()) {
+ warnln("Failed to parse GML: {}", formatted_gml_or_error.error());
return false;
}
+ auto formatted_gml = formatted_gml_or_error.release_value();
if (inplace && !read_from_stdin) {
if (!file->seek(0) || !file->truncate(0)) {
warnln("Could not truncate {}: {}", path, file->error_string());