jimbraun / XCDF

XCDF: eXplicitly Compacted Data Format. See documentation at Read the Docs:
https://xcdf.readthedocs.io/en/latest/
Other
14 stars 8 forks source link

Opening an incompatible file with Python does not return an exception #108

Open HealthyPear opened 9 months ago

HealthyPear commented 9 months ago
from xcdf import xcdf

file = xcdf.File(str("some.incompatible.file.path"), "r")

returns just a print statement, which is not safe.

XCDF ERROR: Unable to open some.incompatible.file.path for reading

To get an actual exception one needs to explicitly call the check() method

In [11]: file.check()
XCDF FATAL ERROR: /private/var/folders/2z/142033n17rbfy969s6h4hymw0000gn/T/pip-req-build-qwktjwel/src/XCDFFile.cc,Read:666]: XCDF Read Failed: File not opened for reading
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[11], line 1
----> 1 file.check()

RuntimeError: Caught an unknown exception!

so this step should be directly part of the opening process, possibly with a better exception than a generic RuntimeError.