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

adapter.aasx: improve error messages #222

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion basyx/aas/adapter/aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ def __init__(self, file: Union[os.PathLike, str, IO]):
closing under any circumstances.

:param file: A filename, file path or an open file-like object in binary mode
:raises FileNotFoundError: If the file does not exist
:raises ValueError: If the file is not a valid OPC zip package
"""
try:
logger.debug("Opening {} as AASX pacakge for reading ...".format(file))
self.reader = pyecma376_2.ZipPackageReader(file)
except FileNotFoundError:
raise
except Exception as e:
raise ValueError("{} is not a valid ECMA376-2 (OPC) file".format(file)) from e
raise ValueError("{} is not a valid ECMA376-2 (OPC) file: {}".format(file, e)) from e

def get_core_properties(self) -> pyecma376_2.OPCCoreProperties:
"""
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/compliance_tool/compliance_check_aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def check_deserialization(file_path: str, state_manager: ComplianceToolStateMana
# open given file
reader = aasx.AASXReader(file_path)
state_manager.set_step_status_from_log()
except ValueError as error:
except (FileNotFoundError, ValueError) as error:
logger.error(error)
state_manager.set_step_status_from_log()
state_manager.add_step('Read file')
Expand Down
2 changes: 1 addition & 1 deletion test/compliance_tool/test_compliance_check_aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_check_deserialization(self) -> None:
compliance_tool.check_deserialization(file_path_1, manager)
self.assertEqual(2, len(manager.steps))
self.assertEqual(Status.FAILED, manager.steps[0].status)
self.assertIn("is not a valid ECMA376-2 (OPC) file", manager.format_step(0, verbose_level=1))
self.assertIn("No such file or directory", manager.format_step(0, verbose_level=1))
self.assertEqual(Status.NOT_EXECUTED, manager.steps[1].status)

# Todo add more tests for checking wrong aasx files
Expand Down
Loading