Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError - Unexpected top-level list aas:assetAdministrationShells on line 3 #190

Closed
WelliSolutions opened this issue Dec 18, 2023 · 2 comments · Fixed by #191
Closed
Labels
enhancement Enhancement of an existing feature

Comments

@WelliSolutions
Copy link

WelliSolutions commented Dec 18, 2023

Background

I'm trying to open the AASX example files from https://admin-shell-io.com/samples/ Unfortunately, those files all suffer from Bug 666 and Bug 681 of AAS Package Explorer. I fixed those bugs in the files manually.

My issue

I'm now trying to open the fixed files with basxy-python-sdk. As recommended in issue #189, I am using failsafe=False to open the files in order to detect the bugs above.

With the failsafe flag, however, I get the following error:

TypeError - Unexpected top-level list aas:assetAdministrationShells on line 3

The only place I can imagine that this refers to is the XML document which starts like this:

<?xml version="1.0" encoding="utf-8"?>
<aas:aasenv xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:IEC61360="http://www.admin-shell.io/IEC61360/1/0" xsi:schemaLocation="http://www.admin-shell.io/aas/1/0 AAS.xsd http://www.admin-shell.io/IEC61360/1/0 IEC61360.xsd" xmlns:aas="http://www.admin-shell.io/aas/1/0">
  <aas:assetAdministrationShells>
    <aas:assetAdministrationShell>
      <aas:idShort>Festo_3S7PM0CP4BD</aas:idShort>

If line 1 is the XML declaration, line 2 is aasenv and line 3 is assetAdministrationShells. But why would it be unexpected? Chapter 5.3.9 of the Metamodel specification defines a [0..*] relationship between environment and asset administration shell. Isn't that what I'm seeing in the XML file?

If I'd like to manually fix the file, what would I need to do?

@WelliSolutions
Copy link
Author

The error message appears in line 1432 of xml_deserialization.py

If I understand line 1421 correctly, it will prepend NS_AAS in front of all names. NS_AAS comes from line 17 in _generic.py and is {https://admin-shell.io/aas/3/0}.

The output for the error message is beautified using _element_pretty_identifier() from line 95 which translates the element name back to the prefix aas:.

So, the only difference I see is that the XML document defines xmlns:aas="http://www.admin-shell.io/aas/1/0" (version 1.0) while the SDK uses XML_NS_MAP = {"aas": "https://admin-shell.io/aas/3/0"} (version 3.0).

In that case, the error message is misleading and it should say: "You are trying to open an AASX file version 1, but the Python SDK can only open AASX files of version 3.".

jkhsjdhjs added a commit to rwth-iat/basyx-python-sdk that referenced this issue Dec 19, 2023
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix eclipse-basyx#190
jkhsjdhjs added a commit to rwth-iat/basyx-python-sdk that referenced this issue Dec 19, 2023
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix eclipse-basyx#190
See also: 79a8635
@jkhsjdhjs
Copy link
Contributor

Yep, the error messages definitely aren't helpful in this case! I created #191, which checks the declared namespaces prior to deserialization and also only replaces the namespace by its prefix in error messages if the namespace is the same as the one expected by our SDK.

s-heppner pushed a commit that referenced this issue Dec 19, 2023
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix #190
s-heppner pushed a commit that referenced this issue Dec 19, 2023
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix #190
See also: 79a8635
@s-heppner s-heppner added the enhancement Enhancement of an existing feature label Dec 19, 2023
jkhsjdhjs added a commit to rwth-iat/basyx-python-sdk that referenced this issue Dec 19, 2023
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix eclipse-basyx#190
jkhsjdhjs added a commit to rwth-iat/basyx-python-sdk that referenced this issue Dec 19, 2023
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix eclipse-basyx#190
See also: 79a8635
s-heppner pushed a commit that referenced this issue Dec 22, 2023
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix #190
s-heppner pushed a commit that referenced this issue Dec 22, 2023
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix #190
See also: 79a8635
somsonson pushed a commit to rwth-iat/basyx-python-framework that referenced this issue Sep 26, 2024
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix eclipse-basyx/basyx-python-sdk#190
somsonson pushed a commit to rwth-iat/basyx-python-framework that referenced this issue Sep 26, 2024
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix eclipse-basyx/basyx-python-sdk#190
See also: 79a86352bb52b1528a9bf9c860331915b4db7556
somsonson pushed a commit to rwth-iat/basyx-python-framework that referenced this issue Dec 9, 2024
Previously, if the elements of an XML document are part of an unknown
namespace, this would lead to cryptic error messages such as:

Unexpected top-level list aas:assetAdministrationShells on line 3

where, the correct expected element is indeed
aas:assetAdministrationShells, leaving the user wondering about what
could possibly be wrong. The only difference is the namespace, which
isn't part of the error message, because it gets replaced by the prefix.

To improve the error messages in this case, a check that compares the
namespaces declared on the document against the ones required by the
deserialization, and errors if a required namespace isn't declared.

Partially fix eclipse-basyx/basyx-python-sdk#190
somsonson pushed a commit to rwth-iat/basyx-python-framework that referenced this issue Dec 9, 2024
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix eclipse-basyx/basyx-python-sdk#190
See also: 79a86352bb52b1528a9bf9c860331915b4db7556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of an existing feature
Projects
None yet
3 participants