Skip to content

Commit

Permalink
Report unexpected text in XML sequences in C# (#389)
Browse files Browse the repository at this point in the history
Currently, we break out of the loop when parsing sequences of
XML elements representing properties of an instances. This gives
misleading error messages ("required property not set").

Instead, with this patch, we report that the text is unexpected, which
is much clearer to the user.
  • Loading branch information
mristin committed Jun 24, 2023
1 parent e2b793f commit 607f65c
Show file tree
Hide file tree
Showing 2 changed files with 703 additions and 313 deletions.
26 changes: 18 additions & 8 deletions aas_core_codegen/csharp/xmlization/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,25 @@ def _generate_deserialize_impl_cls_from_sequence(
blocks_for_non_empty.append(
Stripped(
f"""\
while (reader.NodeType == Xml.XmlNodeType.Element)
while (true)
{{
{I}SkipNoneWhitespaceAndComments(reader);
{I}if (reader.NodeType == Xml.XmlNodeType.EndElement || reader.EOF)
{I}{{
{II}break;
{I}}}
{I}if (reader.NodeType != Xml.XmlNodeType.Element)
{I}{{
{II}error = new Reporting.Error(
{III}"Expected an XML start element representing " +
{III}"a property of an instance of class {name}, " +
{III}$"but got the node of type {{reader.NodeType}} " +
{III}$"with the value {{reader.Value}}");
{II}return null;
{I}}}
{I}string elementName = TryElementName(
{II}reader, out error);
{I}if (error != null)
Expand Down Expand Up @@ -682,13 +699,6 @@ def _generate_deserialize_impl_cls_from_sequence(
{II}}}
{II}// Skip the expected end element
{II}reader.Read();
{II}SkipNoneWhitespaceAndComments(reader);
{I}}}
{I}if (reader.EOF)
{I}{{
{II}break;
{I}}}
}}"""
)
Expand Down
Loading

0 comments on commit 607f65c

Please sign in to comment.