Skip to content

Commit 95256f7

Browse files
authored
Raise a GMTTypeError when an invalid type is passed to 'position' (#4379)
1 parent b0f364d commit 95256f7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

pygmt/src/_common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, ClassVar, Literal
99

10-
from pygmt.exceptions import GMTInvalidInput, GMTValueError
10+
from pygmt.exceptions import GMTInvalidInput, GMTTypeError, GMTValueError
1111
from pygmt.params.position import Position
1212
from pygmt.src.which import which
1313

@@ -337,7 +337,7 @@ def _parse_position(
337337
... )
338338
Traceback (most recent call last):
339339
...
340-
pygmt.exceptions.GMTInvalidInput: Invalid type for parameter 'position':...
340+
pygmt.exceptions.GMTTypeError: Unrecognized data type: <class 'int'>. ...
341341
342342
>>> # Below are examples without kwdict (for new functions).
343343
>>> _parse_position(
@@ -388,6 +388,11 @@ def _parse_position(
388388
case None: # Set default position.
389389
position = default
390390
case _:
391-
msg = f"Invalid type for parameter 'position': {type(position)}."
392-
raise GMTInvalidInput(msg)
391+
raise GMTTypeError(
392+
type(position),
393+
reason=(
394+
"Parameter 'position' must be a Position object, "
395+
"a two-value sequence, a justification code, or None."
396+
),
397+
)
393398
return position

0 commit comments

Comments
 (0)