Skip to content

Commit

Permalink
commands: fix "no workspace" and other error paths
Browse files Browse the repository at this point in the history
Commit 2ac3e27
("WestCommand: use Configuration objects") introduced a
configuration attribute to WestCommand instances, and used
it to look up configuration options.

However, it stored this attribute at the wrong time in
WestCommand.run(). We need to stash the configuration before doing
anything else, because otherwise calls like self.die() in the same
method will look up self.color_ui, which looks up the configuration,
which isn't present, which calls self.die(), leading to an infinite
recursion.

If we stash the configuration immediately, we instead have a valid
configuration option and we get an error printed instead.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
  • Loading branch information
mbolivar-nordic authored and carlescufi committed Feb 20, 2023
1 parent 9c80e89 commit 354b0e8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/west/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ def run(self, args: argparse.Namespace, unknown: List[str],
:param config: `west.configuration.Configuration` or ``None``,
accessible as ``self.config`` from `WestCommand.do_run`
'''
self.config = config
if unknown and not self.accepts_unknown_args:
self.parser.error(f'unexpected arguments: {unknown}')
if not topdir and self.requires_workspace:
self.die(_no_topdir_msg(os.getcwd(), self.name))
self.topdir = os.fspath(topdir) if topdir else None
self.manifest = manifest
self.config = config
for hook in self._hooks:
hook(self)
self.do_run(args, unknown)
Expand Down

0 comments on commit 354b0e8

Please sign in to comment.