Skip to content

Commit

Permalink
config: upgrade dbg to err on missing option
Browse files Browse the repository at this point in the history
A user has pointed out that west's behavior in the following case is
confusing:

  west config foo.bar=baz

The desired behavior is "set foo.bar to baz". Instead, west exits 1
without printing anything on the console.

Let's make it clearer that the user is inadventently asking for the
value of an option called "foo.bar=baz", since right now there is no
rule forbidding "=" in option names, so the above confusing case is
actually asking for section "foo", key "bar=baz".

With this patch, west prints:

  ERROR: foo.bar=baz is unset

to stderr along with exiting 1, making it clearer that something went
wrong.

Note that since this doesn't print to stdout, the new output won't be
confused with the value of the option by well-behaved programs. In
general, 'west config' documents no guarantees about when it prints to
stderr, and new error messages showing up on stderr is in line with
general de facto standard expectations for command line programs.
However, users may need to redirect stderr to /dev/null (or do
similarly on Windows) now if they aren't interested in this output.

Reported-by: David Brown <[email protected]>
Signed-off-by: Martí Bolívar <[email protected]>
  • Loading branch information
mbolivar authored and marc-hb committed Jan 14, 2025
1 parent 3ab7d2f commit 950fc32
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/west/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def read(self, args):
if value is not None:
self.inf(value)
else:
self.dbg(f'{args.name} is unset')
self.err(f'{args.name} is unset')
raise CommandError(returncode=1)

def append(self, args):
Expand Down

0 comments on commit 950fc32

Please sign in to comment.