|
7 | 7 |
|
8 | 8 | import argparse |
9 | 9 | import logging |
10 | | -from os import getcwd, path |
| 10 | +from os import close, getcwd, path |
11 | 11 | from subprocess import CalledProcessError |
| 12 | +import tempfile |
12 | 13 | import textwrap |
| 14 | +import traceback |
13 | 15 |
|
14 | 16 | from west import cmake |
15 | 17 | from west import log |
16 | 18 | from west import util |
17 | 19 | from build_helpers import find_build_dir, is_zephyr_build, \ |
18 | 20 | FIND_BUILD_DIR_DESCRIPTION |
19 | | -from west.commands import CommandContextError |
| 21 | +from west.commands import CommandError |
20 | 22 |
|
21 | 23 | from runners import get_runner_cls, ZephyrBinaryRunner, MissingProgram |
22 | 24 |
|
@@ -184,6 +186,13 @@ def _build_dir(args, die_if_none=True): |
184 | 186 | else: |
185 | 187 | return None |
186 | 188 |
|
| 189 | +def dump_traceback(): |
| 190 | + # Save the current exception to a file and return its path. |
| 191 | + fd, name = tempfile.mkstemp(prefix='west-exc-', suffix='.txt') |
| 192 | + close(fd) # traceback has no use for the fd |
| 193 | + with open(name, 'w') as f: |
| 194 | + traceback.print_exc(file=f) |
| 195 | + log.inf("An exception trace has been saved in", name) |
187 | 196 |
|
188 | 197 | def do_run_common(command, args, runner_args, cached_runner_var): |
189 | 198 | if args.context: |
@@ -224,10 +233,9 @@ def do_run_common(command, args, runner_args, cached_runner_var): |
224 | 233 | runner = args.runner or cache.get(cached_runner_var) |
225 | 234 |
|
226 | 235 | if runner is None: |
227 | | - raise CommandContextError(textwrap.dedent(""" |
228 | | - No {} runner available for {}. Please either specify one |
229 | | - manually, or check your board's documentation for |
230 | | - alternative instructions.""".format(command_name, board))) |
| 236 | + log.die('No', command_name, 'runner available for board', board, |
| 237 | + '({} is not in the cache).'.format(cached_runner_var), |
| 238 | + "Check your board's documentation for instructions.") |
231 | 239 |
|
232 | 240 | _banner('west {}: using runner {}'.format(command_name, runner)) |
233 | 241 | if runner not in available: |
@@ -277,6 +285,10 @@ def do_run_common(command, args, runner_args, cached_runner_var): |
277 | 285 | runner = runner_cls.create(cfg, parsed_args) |
278 | 286 | try: |
279 | 287 | runner.run(command_name) |
| 288 | + except ValueError as ve: |
| 289 | + log.err(str(ve), fatal=True) |
| 290 | + dump_traceback() |
| 291 | + raise CommandError(1) |
280 | 292 | except MissingProgram as e: |
281 | 293 | log.die('required program', e.filename, |
282 | 294 | 'not found; install it or add its location to PATH') |
|
0 commit comments