Skip to content

Commit fc352ca

Browse files
authored
Raise an exception if the given parameter is not recognized and is longer than 2 characters (#1792)
1 parent 4186400 commit fc352ca

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pygmt/helpers/utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,20 @@ def build_arg_string(kwargs):
172172
... )
173173
... )
174174
-BWSen -Bxaf -Byaf -I1/1p,blue -I2/0.25p,blue -JX4i -R1/2/3/4
175+
>>> print(build_arg_string(dict(R="1/2/3/4", J="X4i", watre=True)))
176+
Traceback (most recent call last):
177+
...
178+
pygmt.exceptions.GMTInvalidInput: Unrecognized parameter 'watre'.
175179
"""
176180
gmt_args = []
177-
# Exclude arguments that are None and False
178-
filtered_kwargs = {
179-
k: v for k, v in kwargs.items() if (v is not None and v is not False)
180-
}
181-
for key in filtered_kwargs:
182-
if is_nonstr_iter(kwargs[key]):
183-
for value in kwargs[key]:
184-
gmt_args.append(f"-{key}{value}")
181+
182+
for key in kwargs:
183+
if len(key) > 2: # raise an exception for unrecognized options
184+
raise GMTInvalidInput(f"Unrecognized parameter '{key}'.")
185+
if kwargs[key] is None or kwargs[key] is False:
186+
pass # Exclude arguments that are None and False
187+
elif is_nonstr_iter(kwargs[key]):
188+
gmt_args.extend(f"-{key}{value}" for value in kwargs[key])
185189
elif kwargs[key] is True:
186190
gmt_args.append(f"-{key}")
187191
else:

0 commit comments

Comments
 (0)