|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import contextlib |
3 | 4 | import logging
|
4 | 5 | import os
|
5 | 6 | from dataclasses import dataclass, field
|
@@ -182,6 +183,13 @@ class Command:
|
182 | 183 |
|
183 | 184 | def format_and_rethrow_exception(e: BaseException, component=False):
|
184 | 185 | """Raises a FormattedErrorMessage from the given exception"""
|
| 186 | + ConanException = None |
| 187 | + with contextlib.suppress(ImportError): |
| 188 | + from conan.errors import ( # type: ignore[import-untyped] # noqa: PLC0415 |
| 189 | + ConanException as ConanException_, |
| 190 | + ) |
| 191 | + |
| 192 | + ConanException = ConanException_ # intermediate step to keep mypy happy |
185 | 193 | if isinstance(e, FormattedErrorMessage):
|
186 | 194 | raise e
|
187 | 195 | if isinstance(e, ConfigError):
|
@@ -216,6 +224,15 @@ def format_and_rethrow_exception(e: BaseException, component=False):
|
216 | 224 | "\n\t(scroll up for subprocess output, above Python backtrace)"
|
217 | 225 | )
|
218 | 226 | raise FormattedErrorMessage(msg) from e
|
| 227 | + elif ConanException is not None and isinstance(e, ConanException): |
| 228 | + logger.error("Conan failed", exc_info=False) |
| 229 | + msg = "Conan failed" |
| 230 | + msg = ( |
| 231 | + f"\n\n\t\u274c {msg}:\n\n" |
| 232 | + f"\t\t{e}\n" |
| 233 | + "\n\t(scroll up for subprocess output, above Python backtrace)" |
| 234 | + ) |
| 235 | + raise FormattedErrorMessage(msg) from e |
219 | 236 | elif isinstance(e, AssertionError):
|
220 | 237 | logger.error("Internal error:", exc_info=e)
|
221 | 238 | msg = (
|
|
0 commit comments