Skip to content

Commit

Permalink
Fix error message in C# xmlization on declarations
Browse files Browse the repository at this point in the history
When we encountered XML declarations, we threw exceptions with
uninformative messages. Namely, we expect the reader to be moved to the
content, but most users omitted to read that in the documentation.

We refine the error message for this particular situation, and hint at
`MoveToContent` method on the reader.

See [this aas-core3.0-csharp issue] for more details.

[this aas-core3.0-csharp issue]: aas-core-works/aas-core3.0-csharp#24
  • Loading branch information
mristin committed Nov 9, 2023
1 parent fe69c9f commit 98a9666
Show file tree
Hide file tree
Showing 2 changed files with 574 additions and 2 deletions.
13 changes: 12 additions & 1 deletion aas_core_codegen/csharp/xmlization/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,17 @@ def _generate_deserialize_from(name: Identifier) -> Stripped:
public static Aas.{name} {name}From(
{I}Xml.XmlReader reader)
{{
{I}DeserializeImplementation.SkipNoneWhitespaceAndComments(reader);
{I}if (!reader.EOF && reader.NodeType == Xml.XmlNodeType.XmlDeclaration)
{I}{{
{II}throw new Xmlization.Exception(
{III}"",
{III}"Unexpected XML declaration when reading an instance " +
{III}"of class {name}, as we expect the reader " +
{III}"to be set at content with MoveToContent");
{I}}}
{I}Aas.{name}? result = (
{II}DeserializeImplementation.{name}FromElement(
{III}reader,
Expand Down Expand Up @@ -1879,7 +1890,7 @@ def generate(
{I}public readonly string Path;
{I}public readonly string Cause;
{I}public Exception(string path, string cause)
{II}: base($"{{cause}} at: {{path}}")
{II}: base($"{{cause}} at: {{(path == "" ? "the beginning" : path)}}")
{I}{{
{II}Path = path;
{II}Cause = cause;
Expand Down
Loading

0 comments on commit 98a9666

Please sign in to comment.