nanograv / PINT

PINT is not TEMPO3 -- Software for high-precision pulsar timing
Other
121 stars 101 forks source link

Define all exceptions in one place? #1839

Closed dlakaplan closed 1 month ago

dlakaplan commented 2 months ago

It looks like PINT has 19 or so custom exceptions defined in various places:

src/pint/fitter.py:class ConvergenceFailure(ValueError):
src/pint/fitter.py:class CorrelatedErrors(ValueError):
src/pint/utils.py:class PINTPrecisionError(RuntimeError):
src/pint/utils.py:class PrefixError(ValueError):
src/pint/models/model_builder.py:class ComponentConflict(ValueError):
src/pint/models/noise_model.py:class ScaleToaError(NoiseComponent):
src/pint/models/noise_model.py:class ScaleDmError(NoiseComponent):
src/pint/models/parameter.py:class InvalidModelParameters(ValueError):
src/pint/observatory/__init__.py:class ClockCorrectionError(RuntimeError):
src/pint/observatory/__init__.py:class NoClockCorrections(ClockCorrectionError):
src/pint/observatory/__init__.py:class ClockCorrectionOutOfRange(ClockCorrectionError):
src/pint/models/timing_model.py:class MissingTOAs(ValueError):
src/pint/models/timing_model.py:class PropertyAttributeError(ValueError):
src/pint/models/timing_model.py:class TimingModelError(ValueError):
src/pint/models/timing_model.py:class MissingParameter(TimingModelError):
src/pint/models/timing_model.py:class AliasConflict(TimingModelError):
src/pint/models/timing_model.py:class UnknownParameter(TimingModelError):
src/pint/models/timing_model.py:class UnknownBinaryModel(TimingModelError):
src/pint/models/timing_model.py:class MissingBinaryError(TimingModelError):

Basically these are defined in the module where they are largely used. But if we wanted to use them more widely we might run in to import issues (circular imports, etc). Would it be better to have an exceptions.py that just has this code and minimal other dependencies so that it can be imported and used PINT-wide? I don't know if this is in general a good practice or not.