echemdb / svgdigitizer

(x,y) Data Points from SVG files
https://echemdb.github.io/svgdigitizer/
GNU General Public License v3.0
17 stars 8 forks source link

Fix exception handling #175

Closed DunklesArchipel closed 1 year ago

DunklesArchipel commented 1 year ago

Checklist

The new version of pylint does not allow raising general exceptions.

saraedum commented 1 year ago

I believe that technically none of these are ValueError:

Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.

The error here is never about the argument. I guess virtually all of these are saying that the data parsed does not contain this information or that the data is inconsistent (duplicate value errors.)

Maybe it's worth our while to create exception classes for this? Something like

class DataSufficiencyError(RuntimeError): pass
class DataConsistencyError(RuntimeError): pass

(I am not sold on that "sufficiency" term though…)

DunklesArchipel commented 1 year ago

How about

class SVGAnnotationError: pass

Example:

The following exception: raise Exception("No current axis or more than one current axis found.")

would read: raise SVGAnnotationError("No current axis or more than one current axis found in the SVG.")

DunklesArchipel commented 1 year ago

@saraedum since I never handled exceptions that accurately it would be great to hear your thoughts about the approach.

I created a new module for the errors, which I would import into the svgdigitizer modules. Currently, this is only implemented in svgplot.curve. (This seems to be a tricky one anyway). The errors will then contain the doctests for the different Errors and could be removed from the main modules.

I hope this is how it should be done... :)

saraedum commented 1 year ago

@DunklesArchipel if the tests pass, then this is ready I think.