Currently, we have several exceptions defined in https://github.com/GenericMappingTools/pygmt/blob/main/pygmt/exceptions.py.
Below is a simple command to count how often each exception is raised in the codebase (The tests directory and the exceptions.py file are excluded).
for e in \
GMTError \
GMTOSError \
GMTCLibError \
GMTCLibNotFoundError \
GMTCLibNoSessionError \
GMTVersionError \
GMTInvalidInput \
GMTImageComparisonFailure;
do
n=$(grep -R --exclude-dir=tests --exclude="exceptions.py" "raise $e" pygmt | wc -l)
echo "$e: $n"
done
the output is:
GMTError: 1
GMTOSError: 1
GMTCLibError: 16
GMTCLibNotFoundError: 1
GMTCLibNoSessionError: 1
GMTVersionError: 1
GMTInvalidInput: 87
GMTImageComparisonFailure: 1
Most exceptions are about the GMT C library, and is only used once or a few times. But the GMTInvalidInput exception is used 87 times and will definitely increase as we wrap more modules.
The GMTInvalidInput exception is general and doesn't tell exactly what's happening. I haven't checked the source codes carefully, but I feel the exceptions can be grouped into a few categories:
- A required parameter is not given
- Given parameters have conflicts
- A parameter is given with an incorrect type
- A parameter is given with invalid values
- Maybe more
I think we should have more accurate exceptions, e.g.,
The exception may even start with PYGMT, not GMT, since these are not directly related to GMT.
Currently, we have several exceptions defined in https://github.com/GenericMappingTools/pygmt/blob/main/pygmt/exceptions.py.
Below is a simple command to count how often each exception is raised in the codebase (The
testsdirectory and theexceptions.pyfile are excluded).the output is:
Most exceptions are about the GMT C library, and is only used once or a few times. But the
GMTInvalidInputexception is used 87 times and will definitely increase as we wrap more modules.The
GMTInvalidInputexception is general and doesn't tell exactly what's happening. I haven't checked the source codes carefully, but I feel the exceptions can be grouped into a few categories:I think we should have more accurate exceptions, e.g.,
GMTParameterError: for cases 1 and 2, maybe having more fine-grain exceptions likeGMTRequiredParameterError/GMTConflictParameterErrorGMTTypeError: for case 3, similar to the built-inTypeErrorBREAKING: Raise GMTTypeError exception for invalid types. Previously raise GMTInvalidInput #3999GMTValueError: for case 4, similar to the built-inValueErrorBREAKING: Raise GMTValueError exception for invalid values. Previously raise GMTInvalidInput #3985The exception may even start with
PYGMT, notGMT, since these are not directly related to GMT.