Skip to content

Commit

Permalink
improve error message on invalid formatting of shell options
Browse files Browse the repository at this point in the history
Problem: When submitting a job through the command line, a shell
option `-o KEY[=VAL]` is not required to have a value. If one is
not provided, then `attributes.system.shell.KEY` is set to 1. If a
user later provides a sub-key of this shell option, such as `-o
KEY.foo=bar`, the error message returned by Python is not
particularly helpful.

Wrap `set_treedict()` in a try/except where user input might
provide an invalid key and raise a useful error message.
Fixes #6678
  • Loading branch information
wihobbs committed Mar 3, 2025
1 parent 1476d28 commit abc368f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/bindings/python/flux/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ def update_keyval(self, keyval):
value = json.loads(value)
except json.decoder.JSONDecodeError:
value = str(value)
set_treedict(self.config, key, value)
try:
set_treedict(self.config, key, value)
except TypeError as e:
raise TypeError(f"failed to set {key} to {value}: {e}")
return self

def update_file(self, path, extension=".toml"):
Expand Down
5 changes: 4 additions & 1 deletion src/bindings/python/flux/job/Jobspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ def setattr(self, key, val):
if not key.startswith(("user.", "system.")):
key = "system." + key
key = "attributes." + key
set_treedict(self.jobspec, key, val)
try:
set_treedict(self.jobspec, key, val)
except TypeError as e:
raise TypeError(f"failed to set {key} to {val}: {e}")

def setattr_shell_option(self, key, val):
"""
Expand Down

0 comments on commit abc368f

Please sign in to comment.