Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands: Show less generic error when no manifest is loaded #671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/west/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
SelfUpdate, ForAll, Init, Update, Topdir
from west.app.config import Config
from west.manifest import Manifest, MalformedConfig, MalformedManifest, \
ManifestVersionError, ManifestImportFailed, _ManifestImportDepth, \
ManifestProject, MANIFEST_REV_BRANCH
_ManifestRequired, ManifestVersionError, ManifestImportFailed, \
_ManifestImportDepth, ManifestProject, MANIFEST_REV_BRANCH
from west.util import quote_sh_list, west_topdir, WestNotFound
from west.version import __version__

Expand Down Expand Up @@ -608,9 +608,18 @@ def run_builtin(self, args, unknown):
self.handle_builtin_manifest_load_err(args)
for io_hook in self.queued_io:
self.cmd.add_pre_run_hook(io_hook)
self.cmd.run(args, unknown, self.topdir,
manifest=self.manifest,
config=self.config)
try:
self.cmd.run(args, unknown, self.topdir,
manifest=self.manifest,
config=self.config)
except _ManifestRequired:
# We tried to run the command despite having failed to
# load_manifest(), but the manifest was needed after all.
# Show the deferred exception and exit.
if self.mle.args:
self.cmd.die('\n '.join(str(arg) for arg in self.mle.args))
else:
self.cmd.die(str(self.mle))

def run_extension(self, name, argv):
# Check a program invariant. We should never get here
Expand Down
6 changes: 2 additions & 4 deletions src/west/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import yaml

from west.configuration import Configuration
from west.manifest import Manifest, Project
from west.manifest import Manifest, _ManifestRequired, Project
from west.util import escapes_directory, quote_sh_list, PathType

'''\
Expand Down Expand Up @@ -258,9 +258,7 @@ def _get_manifest(self) -> Manifest:
Otherwise, a fatal error occurs.
'''
if self._manifest is None:
self.die(f"can't run west {self.name};",
"it requires the manifest, which was not available.",
'Try "west manifest --validate" to debug.')
raise _ManifestRequired
return self._manifest

def _set_manifest(self, manifest: Optional[Manifest]):
Expand Down
4 changes: 4 additions & 0 deletions src/west/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ class _ManifestImportDepth(ManifestImportFailed):
# A hack to signal to main.py what happened.
pass

class _ManifestRequired(Exception):
# A built-in command had to read the manifest but it wasn't loaded.
pass

#
# The main Manifest class and its public helper types, like Project
# and ImportFlag.
Expand Down