cemsbv / pygef

Parse soil measurement data.
https://cemsbv.github.io/pygef
MIT License
31 stars 19 forks source link

read_cpt should return dedicated exception if file is not gef or xml #292

Closed tlukkezen closed 1 year ago

tlukkezen commented 1 year ago

If the user provides a file to read_cpt that is neither in the correct .gef or .xml format, pygef tries to read as an xml and throws confusing exceptions.

Specifically, if a user provides a .gef file with erroneous format, the user gets BroXMLParser exceptions, which makes no sense.

Expected result The user should get an insightful exception (e.g. custom UnknownFileFormatException) that explains that the provided file cannot be parsed as a .gef or .xml

tversteeg commented 1 year ago

What about files that have wrong file extensions but are otherwise correct, such as example.gef.bak?

Maybe another option is to pass an optional flag specifying the type:

read_cpt("example.gef.bak", file_format = FileFormat.GEF)

Where file_format can be FileFormat.GEF, FileFormat.XML or FileFormat.Auto.