aas-core-works / aas-core3.0-python

Manipulate, verify and de/serialize asset administration shells in Python.
Other
4 stars 0 forks source link

File.value - and error handling in general #10

Closed alexgordtop closed 10 months ago

alexgordtop commented 10 months ago

We have a test model with file.value = './test_path/to/file' which results in the following error...

Cause: 'The value must represent a valid file URI scheme according to RFC 8089.', Path: '.submodel_elements[0].value'

DoAAS Pt1 references the following spec: https://datatracker.ietf.org/doc/html/rfc8089#appendix-E.2.1

According to this, our value should be valid - or not?

How do you think about enhancing the Error and Path classes from verification to something like this? I want to be able to print it - another option would be to make it json serializable...

Especially for cloud / server deployment it would be great to also have an "id_short_path" and an "identifier" where applicable - so that we're not forced to debug the structure. And for regex violations, the malformed value would be nice :)

class Path:
    """Represent the relative path to the erroneous value."""

    def __init__(self) -> None:
        """Initialize as an empty path."""
        self._segments = []  # type: List[Segment]

    @property
    def segments(self) -> Sequence[Segment]:
        """Get the segments of the path."""
        return self._segments

    def _prepend(self, segment: Segment) -> None:
        """Insert the :paramref:`segment` in front of other segments."""
        self._segments.insert(0, segment)

    def __str__(self) -> str:
        return "".join(str(segment) for segment in self._segments)

    def __repr__(self) -> str:
        return self.__str__()

class Error:
    """Represent a verification error in the data."""

    #: Human-readable description of the error
    cause: Final[str]

    #: Path to the erroneous value
    path: Final[Path]

    def __init__(self, cause: str) -> None:
        """Initialize as an error with an empty path."""
        self.cause = cause
        self.path = Path()

    def __str__(self) -> str:
        return f"\nCause: '{self.cause}', Path: '{self.path}'"

    def __repr__(self) -> str:
        return self.__str__()
mristin commented 10 months ago

@alexgordtop the RFC 8089 does not allow for relative paths. This is really unfortunate, and the issue keeps popping up at different places: https://github.com/aas-core-works/aas-core-meta/issues/269 https://github.com/aas-core-works/aas-core3.0-typescript/issues/10

This needs to be clarified with the AAS work stream. Either RFC 8089 paths are enforced, or they are not enforced and any text is allowed.

I forked the second part of the issue to #11.