diff --git a/src/org/openstreetmap/josm/io/OsmReader.java b/src/org/openstreetmap/josm/io/OsmReader.java
index 43bd83c8b6..632e70c74a 100644
--- a/src/org/openstreetmap/josm/io/OsmReader.java
+++ b/src/org/openstreetmap/josm/io/OsmReader.java
@@ -201,6 +201,19 @@ public class OsmReader extends AbstractReader {
         }
     }
 
+    private void parseError() throws XMLStreamException {
+        while (parser.hasNext()) {
+            int event = parser.next();
+            if (event == XMLStreamConstants.CHARACTERS) {
+                throwException(parser.getText());
+            } else if (event == XMLStreamConstants.END_ELEMENT) {
+                return;
+            } else {
+                throwException("Unknown error element type");
+            }
+        }
+    }
+
     private void parseRemark() throws XMLStreamException {
         while (parser.hasNext()) {
             int event = parser.next();
@@ -393,6 +406,8 @@ public class OsmReader extends AbstractReader {
         if (printWarning && ("note".equals(element) || "meta".equals(element))) {
             // we know that Overpass API returns those elements
             Logging.debug(tr("Undefined element ''{0}'' found in input stream. Skipping.", element));
+        } else if ("error".equals(element)) {
+            parseError();
         } else if (printWarning) {
             Logging.info(tr("Undefined element ''{0}'' found in input stream. Skipping.", element));
         }
diff --git a/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java b/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java
index 5c52e2708d..9aa912aef6 100644
--- a/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java
+++ b/test/unit/org/openstreetmap/josm/io/OsmReaderTest.java
@@ -4,9 +4,11 @@ package org.openstreetmap.josm.io;
 import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
@@ -17,6 +19,8 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Arrays;
 
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.openstreetmap.josm.TestUtils;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -135,23 +139,19 @@ class OsmReaderTest {
     private static DataSet testValidData(String osm, Options[] options) throws Exception {
         try (InputStream in = new ByteArrayInputStream(
                 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) {
-            return OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, options);
+            return assertDoesNotThrow(() -> OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE, options));
         }
     }
 
     /**
      * Test invalid data.
      * @param osm OSM data without XML prefix
-     * @param expectedError expected error message
-     * @throws Exception if any error occurs
+     * @return The exception
      */
-    private static void testInvalidData(String osm, String expectedError) throws Exception {
+    private static IllegalDataException testInvalidData(String osm) throws Exception {
         try (InputStream in = new ByteArrayInputStream(
                 ("<?xml version='1.0' encoding='UTF-8'?>" + osm).getBytes(StandardCharsets.UTF_8))) {
-            OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
-            fail("should throw exception");
-        } catch (IllegalDataException e) {
-            assertEquals(expectedError, e.getMessage());
+            return assertThrows(IllegalDataException.class, () -> OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE));
         }
     }
 
@@ -161,8 +161,8 @@ class OsmReaderTest {
      */
     @Test
     void testInvalidUid() throws Exception {
-        testInvalidData("<osm version='0.6'><node id='1' uid='nan'/></osm>",
-                "Illegal value for attribute 'uid'. Got 'nan'. (at line 1, column 82). 82 bytes have been read");
+        assertEquals("Illegal value for attribute 'uid'. Got 'nan'. (at line 1, column 82). 82 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' uid='nan'/></osm>").getMessage());
     }
 
     /**
@@ -171,8 +171,8 @@ class OsmReaderTest {
      */
     @Test
     void testMissingId() throws Exception {
-        testInvalidData("<osm version='0.6'><node/></osm>",
-                "Missing required attribute 'id'. (at line 1, column 65). 64 bytes have been read");
+        assertEquals("Missing required attribute 'id'. (at line 1, column 65). 64 bytes have been read",
+                testInvalidData("<osm version='0.6'><node/></osm>").getMessage());
     }
 
     /**
@@ -181,10 +181,10 @@ class OsmReaderTest {
      */
     @Test
     void testMissingRef() throws Exception {
-        testInvalidData("<osm version='0.6'><way id='1' version='1'><nd/></way></osm>",
-                "Missing mandatory attribute 'ref' on <nd> of way 1. (at line 1, column 87). 88 bytes have been read");
-        testInvalidData("<osm version='0.6'><relation id='1' version='1'><member/></relation></osm>",
-                "Missing attribute 'ref' on member in relation 1. (at line 1, column 96). 101 bytes have been read");
+        assertEquals("Missing mandatory attribute 'ref' on <nd> of way 1. (at line 1, column 87). 88 bytes have been read",
+                testInvalidData("<osm version='0.6'><way id='1' version='1'><nd/></way></osm>").getMessage());
+        assertEquals("Missing attribute 'ref' on member in relation 1. (at line 1, column 96). 101 bytes have been read",
+                testInvalidData("<osm version='0.6'><relation id='1' version='1'><member/></relation></osm>").getMessage());
     }
 
     /**
@@ -193,15 +193,15 @@ class OsmReaderTest {
      */
     @Test
     void testIllegalRef() throws Exception {
-        testInvalidData("<osm version='0.6'><way id='1' version='1'><nd ref='0'/></way></osm>",
-                "Illegal value of attribute 'ref' of element <nd>. Got 0. (at line 1, column 95). 96 bytes have been read");
-        testInvalidData("<osm version='0.6'><way id='1' version='1'><nd ref='nan'/></way></osm>",
-                "Illegal long value for attribute 'ref'. Got 'nan'. (at line 1, column 97). 98 bytes have been read");
-
-        testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='node' ref='0'/></relation></osm>",
-                "Incomplete <member> specification with ref=0 (at line 1, column 116). 121 bytes have been read");
-        testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='node' ref='nan'/></relation></osm>",
-                "Illegal value for attribute 'ref' on member in relation 1. Got nan (at line 1, column 118). 123 bytes have been read");
+        assertEquals("Illegal value of attribute 'ref' of element <nd>. Got 0. (at line 1, column 95). 96 bytes have been read",
+                testInvalidData("<osm version='0.6'><way id='1' version='1'><nd ref='0'/></way></osm>").getMessage());
+        assertEquals("Illegal long value for attribute 'ref'. Got 'nan'. (at line 1, column 97). 98 bytes have been read",
+                testInvalidData("<osm version='0.6'><way id='1' version='1'><nd ref='nan'/></way></osm>").getMessage());
+
+        assertEquals("Incomplete <member> specification with ref=0 (at line 1, column 116). 121 bytes have been read",
+                testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='node' ref='0'/></relation></osm>").getMessage());
+        assertEquals("Illegal value for attribute 'ref' on member in relation 1. Got nan (at line 1, column 118). 123 bytes have been read",
+                testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='node' ref='nan'/></relation></osm>").getMessage());
     }
 
     /**
@@ -210,8 +210,8 @@ class OsmReaderTest {
      */
     @Test
     void testMissingType() throws Exception {
-        testInvalidData("<osm version='0.6'><relation id='1' version='1'><member ref='1'/></relation></osm>",
-                "Missing attribute 'type' on member 1 in relation 1. (at line 1, column 104). 109 bytes have been read");
+        assertEquals("Missing attribute 'type' on member 1 in relation 1. (at line 1, column 104). 109 bytes have been read",
+                testInvalidData("<osm version='0.6'><relation id='1' version='1'><member ref='1'/></relation></osm>").getMessage());
     }
 
     /**
@@ -220,8 +220,8 @@ class OsmReaderTest {
      */
     @Test
     void testIllegalType() throws Exception {
-        testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='foo' ref='1'/></relation></osm>",
-                "Illegal value for attribute 'type' on member 1 in relation 1. Got foo. (at line 1, column 115). 120 bytes have been read");
+        assertEquals("Illegal value for attribute 'type' on member 1 in relation 1. Got foo. (at line 1, column 115). 120 bytes have been read",
+                testInvalidData("<osm version='0.6'><relation id='1' version='1'><member type='foo' ref='1'/></relation></osm>").getMessage());
     }
 
     /**
@@ -230,12 +230,12 @@ class OsmReaderTest {
      */
     @Test
     void testMissingKeyValue() throws Exception {
-        testInvalidData("<osm version='0.6'><node id='1' version='1'><tag/></node></osm>",
-                "Missing key or value attribute in tag. (at line 1, column 89). 89 bytes have been read");
-        testInvalidData("<osm version='0.6'><node id='1' version='1'><tag k='foo'/></node></osm>",
-                "Missing key or value attribute in tag. (at line 1, column 97). 97 bytes have been read");
-        testInvalidData("<osm version='0.6'><node id='1' version='1'><tag v='bar'/></node></osm>",
-                "Missing key or value attribute in tag. (at line 1, column 97). 97 bytes have been read");
+        assertEquals("Missing key or value attribute in tag. (at line 1, column 89). 89 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='1'><tag/></node></osm>").getMessage());
+        assertEquals("Missing key or value attribute in tag. (at line 1, column 97). 97 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='1'><tag k='foo'/></node></osm>").getMessage());
+        assertEquals("Missing key or value attribute in tag. (at line 1, column 97). 97 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='1'><tag v='bar'/></node></osm>").getMessage());
     }
 
     /**
@@ -244,10 +244,10 @@ class OsmReaderTest {
      */
     @Test
     void testMissingVersion() throws Exception {
-        testInvalidData("<osm/>",
-                "Missing mandatory attribute 'version'. (at line 1, column 45). 44 bytes have been read");
-        testInvalidData("<osm version='0.6'><node id='1'/></osm>",
-                "Missing attribute 'version' on OSM primitive with ID 1. (at line 1, column 72). 72 bytes have been read");
+        assertEquals("Missing mandatory attribute 'version'. (at line 1, column 45). 44 bytes have been read",
+                testInvalidData("<osm/>").getMessage());
+        assertEquals("Missing attribute 'version' on OSM primitive with ID 1. (at line 1, column 72). 72 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1'/></osm>").getMessage());
     }
 
     /**
@@ -256,8 +256,8 @@ class OsmReaderTest {
      */
     @Test
     void testUnsupportedVersion() throws Exception {
-        testInvalidData("<osm version='0.1'/>",
-                "Unsupported version: 0.1 (at line 1, column 59). 58 bytes have been read");
+        assertEquals("Unsupported version: 0.1 (at line 1, column 59). 58 bytes have been read",
+                testInvalidData("<osm version='0.1'/>").getMessage());
     }
 
     /**
@@ -266,8 +266,8 @@ class OsmReaderTest {
      */
     @Test
     void testIllegalVersion() throws Exception {
-        testInvalidData("<osm version='0.6'><node id='1' version='nan'/></osm>",
-                "Illegal value for attribute 'version' on OSM primitive with ID 1. Got nan. (at line 1, column 86). 86 bytes have been read");
+        assertEquals("Illegal value for attribute 'version' on OSM primitive with ID 1. Got nan. (at line 1, column 86). 86 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='nan'/></osm>").getMessage());
     }
 
     /**
@@ -276,10 +276,10 @@ class OsmReaderTest {
      */
     @Test
     void testIllegalChangeset() throws Exception {
-        testInvalidData("<osm version='0.6'><node id='1' version='1' changeset='nan'/></osm>",
-                "Illegal value for attribute 'changeset'. Got nan. (at line 1, column 100). 100 bytes have been read");
-        testInvalidData("<osm version='0.6'><node id='1' version='1' changeset='-1'/></osm>",
-                "Illegal value for attribute 'changeset'. Got -1. (at line 1, column 99). 99 bytes have been read");
+        assertEquals("Illegal value for attribute 'changeset'. Got nan. (at line 1, column 100). 100 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='1' changeset='nan'/></osm>").getMessage());
+        assertEquals("Illegal value for attribute 'changeset'. Got -1. (at line 1, column 99). 99 bytes have been read",
+                testInvalidData("<osm version='0.6'><node id='1' version='1' changeset='-1'/></osm>").getMessage());
     }
 
     /**
@@ -300,18 +300,18 @@ class OsmReaderTest {
      */
     @Test
     void testInvalidBounds() throws Exception {
-        testInvalidData("<osm version='0.6'><bounds/></osm>",
-                "Missing mandatory attributes on element 'bounds'. " +
-                "Got minlon='null',minlat='null',maxlon='null',maxlat='null', origin='null'. (at line 1, column 67). 72 bytes have been read");
-        testInvalidData("<osm version='0.6'><bounds minlon='0'/></osm>",
-                "Missing mandatory attributes on element 'bounds'. " +
-                "Got minlon='0',minlat='null',maxlon='null',maxlat='null', origin='null'. (at line 1, column 78). 83 bytes have been read");
-        testInvalidData("<osm version='0.6'><bounds minlon='0' minlat='0'/></osm>",
-                "Missing mandatory attributes on element 'bounds'. " +
-                "Got minlon='0',minlat='0',maxlon='null',maxlat='null', origin='null'. (at line 1, column 89). 94 bytes have been read");
-        testInvalidData("<osm version='0.6'><bounds minlon='0' minlat='0' maxlon='1'/></osm>",
-                "Missing mandatory attributes on element 'bounds'. " +
-                "Got minlon='0',minlat='0',maxlon='1',maxlat='null', origin='null'. (at line 1, column 100). 105 bytes have been read");
+        assertEquals("Missing mandatory attributes on element 'bounds'. " +
+                "Got minlon='null',minlat='null',maxlon='null',maxlat='null', origin='null'. (at line 1, column 67). 72 bytes have been read",
+                testInvalidData("<osm version='0.6'><bounds/></osm>").getMessage());
+        assertEquals("Missing mandatory attributes on element 'bounds'. " +
+                "Got minlon='0',minlat='null',maxlon='null',maxlat='null', origin='null'. (at line 1, column 78). 83 bytes have been read",
+                testInvalidData("<osm version='0.6'><bounds minlon='0'/></osm>").getMessage());
+        assertEquals("Missing mandatory attributes on element 'bounds'. " +
+                "Got minlon='0',minlat='0',maxlon='null',maxlat='null', origin='null'. (at line 1, column 89). 94 bytes have been read",
+                testInvalidData("<osm version='0.6'><bounds minlon='0' minlat='0'/></osm>").getMessage());
+        assertEquals("Missing mandatory attributes on element 'bounds'. " +
+                "Got minlon='0',minlat='0',maxlon='1',maxlat='null', origin='null'. (at line 1, column 100). 105 bytes have been read",
+                testInvalidData("<osm version='0.6'><bounds minlon='0' minlat='0' maxlon='1'/></osm>").getMessage());
     }
 
     /**
@@ -404,4 +404,17 @@ class OsmReaderTest {
             }
         }
     }
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "<osm version=\"0.6\"><error>Mismatch in tags key and value size</error></osm>",
+            "<osm version=\"0.6\"><node id=\"1\" visible=\"true\" version=\"1\"><error>Mismatch in tags key and value size</error></node></osm>",
+            "<osm version=\"0.6\"><way id=\"1\" visible=\"true\" version=\"1\"><error>Mismatch in tags key and value size</error></way></osm>",
+            "<osm version=\"0.6\"><way id=\"1\" visible=\"true\" version=\"1\"><error>Mismatch in tags key and value size</error></way></osm>",
+            "<osm version=\"0.6\"><relation id=\"1\" visible=\"true\" version=\"1\"><error>Mismatch in tags key and value size</error></relation></osm>"
+    })
+    void testError(String testData) throws Exception {
+        IllegalDataException illegalDataException = testInvalidData(testData);
+        assertTrue(illegalDataException.getMessage().contains("Mismatch in tags key and value size"));
+    }
 }
