2424)
2525from pygmt .clib .loading import get_gmt_version , load_libgmt
2626from pygmt .datatypes import _GMT_DATASET , _GMT_GRID , _GMT_IMAGE
27- from pygmt .exceptions import GMTCLibError , GMTCLibNoSessionError , GMTInvalidInput
27+ from pygmt .exceptions import (
28+ GMTCLibError ,
29+ GMTCLibNoSessionError ,
30+ GMTInvalidInput ,
31+ GMTValueError ,
32+ )
2833from pygmt .helpers import (
2934 _validate_data_input ,
3035 data_kind ,
@@ -560,11 +565,13 @@ def get_common(self, option: str) -> bool | int | float | np.ndarray:
560565 ... lib.get_common("A")
561566 Traceback (most recent call last):
562567 ...
563- pygmt.exceptions.GMTInvalidInput: Unknown GMT common option flag 'A'.
568+ pygmt.exceptions.GMTValueError: Invalid GMT common option: 'A'. Expected .. .
564569 """
565- if option not in "BIJRUVXYabfghinoprst:" :
566- msg = f"Unknown GMT common option flag '{ option } '."
567- raise GMTInvalidInput (msg )
570+ valid_options = "BIJRUVXYabfghinoprst:"
571+ if option not in valid_options :
572+ raise GMTValueError (
573+ option , description = "GMT common option" , choices = valid_options
574+ )
568575
569576 c_get_common = self .get_libgmt_func (
570577 "GMT_Get_Common" ,
@@ -847,15 +854,15 @@ def _parse_constant(
847854 their values are added.
848855
849856 If no valid modifiers are given, then will assume that modifiers are not
850- allowed. In this case, will raise a :class:`pygmt.exceptions.GMTInvalidInput `
857+ allowed. In this case, will raise a :class:`pygmt.exceptions.GMTValueError `
851858 exception if given a modifier.
852859
853860 Parameters
854861 ----------
855862 constant
856863 The name of a valid GMT API constant, with an optional modifier.
857864 valid
858- A list of valid values for the constant. Will raise a GMTInvalidInput
865+ A list of valid values for the constant. Will raise a GMTValueError
859866 exception if the given value is not in the list.
860867 valid_modifiers
861868 A list of valid modifiers that can be added to the constant. If ``None``,
@@ -866,28 +873,23 @@ def _parse_constant(
866873 nmodifiers = len (parts ) - 1
867874
868875 if name not in valid :
869- msg = f"Invalid constant name '{ name } '. Must be one of { valid } ."
870- raise GMTInvalidInput (msg )
876+ raise GMTValueError (name , description = "constant name" , choices = valid )
871877
872878 match nmodifiers :
873879 case 1 if valid_modifiers is None :
874- msg = (
875- f"Constant modifiers are not allowed since valid values "
876- f" were not given: ' { constant } '."
880+ raise GMTValueError (
881+ constant ,
882+ reason = "Constant modifiers are not allowed since valid values were not given." ,
877883 )
878- raise GMTInvalidInput (msg )
879884 case 1 if valid_modifiers is not None and parts [1 ] not in valid_modifiers :
880- msg = (
881- f"Invalid constant modifier '{ parts [1 ]} '. "
882- f"Must be one of { valid_modifiers } ."
885+ raise GMTValueError (
886+ parts [1 ], description = "constant modifier" , choices = valid_modifiers
883887 )
884- raise GMTInvalidInput (msg )
885888 case n if n > 1 :
886- msg = (
887- f"Only one modifier is allowed in constants, "
888- f" { nmodifiers } given: ' { constant } '."
889+ raise GMTValueError (
890+ constant ,
891+ reason = f"Only one modifier is allowed in constants but { nmodifiers } given." ,
889892 )
890- raise GMTInvalidInput (msg )
891893
892894 integer_value = sum (self [part ] for part in parts )
893895 return integer_value
0 commit comments