diff options
| author | Jules Aguillon | 2023-12-17 12:12:23 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2023-12-17 12:12:23 +0100 |
| commit | 478d8082f41b7859356c3f9662e1c46327b4b76e (patch) | |
| tree | 2e5a9429750e97e536a27d023ed315c667a018a8 | |
| parent | 7af6adcf1132a85bd21339b97fd5fa9c2a731b94 (diff) | |
| download | unexpected-keyboard-478d8082f41b7859356c3f9662e1c46327b4b76e.tar.gz unexpected-keyboard-478d8082f41b7859356c3f9662e1c46327b4b76e.zip | |
Improve layout parsing errors
Add location information to all error and improve "expected tag" errors.
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 9326ad8..989c5f6 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -221,7 +221,7 @@ class KeyboardData private static KeyboardData parse_keyboard(XmlPullParser parser) throws Exception { if (!expect_tag(parser, "keyboard")) - throw new Exception("Empty layout file"); + throw error(parser, "Expected tag <keyboard>"); boolean add_bottom_row = attribute_bool(parser, "bottom_row", true); float specified_kw = attribute_float(parser, "width", 0f); String script = parser.getAttributeValue(null, "script"); @@ -238,7 +238,7 @@ class KeyboardData modmap = Modmap.parse(parser); break; default: - throw new Exception("Unknown tag: " + parser.getName()); + throw error(parser, "Expecting tag <row>, got <" + parser.getName() + ">"); } } float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); @@ -258,7 +258,7 @@ class KeyboardData private static Row parse_row(XmlPullParser parser) throws Exception { if (!expect_tag(parser, "row")) - throw new Exception("Failed to parse row"); + throw error(parser, "Expected tag <row>"); return Row.parse(parser); } @@ -604,7 +604,8 @@ class KeyboardData if (!next_tag(parser)) return false; if (!parser.getName().equals(name)) - throw new Exception("Unknown tag: " + parser.getName()); + throw error(parser, "Expecting tag <" + name + ">, got <" + + parser.getName() + ">"); return true; } @@ -623,4 +624,10 @@ class KeyboardData return default_val; return Float.parseFloat(val); } + + /** Construct a parsing error. */ + private static Exception error(XmlPullParser parser, String message) + { + return new Exception(message + " " + parser.getPositionDescription()); + } } |
