From 776174b478a481d4997f2ef4aa25ece1a07f2631 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Fri, 4 Oct 2024 10:05:56 +0200 Subject: [PATCH] Only use logger.exception for unexpected exceptions --- src/ert/__main__.py | 8 ++++---- src/ert/cli/main.py | 4 ---- src/ert/gui/tools/plot/plot_window.py | 10 +++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ert/__main__.py b/src/ert/__main__.py index 65040fc1b59..1540daaf233 100755 --- a/src/ert/__main__.py +++ b/src/ert/__main__.py @@ -17,7 +17,7 @@ import ert.shared from _ert.threading import set_signal_handler -from ert.cli.main import ErtCliError, ErtTimeoutError, run_cli +from ert.cli.main import ErtCliError, run_cli from ert.config import ConfigValidationError, ErtConfig, lint_file from ert.logging import LOGGING_CONFIG from ert.mode_definitions import ( @@ -679,12 +679,12 @@ def main() -> None: with ErtPluginContext(logger=logging.getLogger()) as context: logger.info(f"Running ert with {args}") args.func(args, context.plugin_manager) - except (ErtCliError, ErtTimeoutError) as err: - logger.exception(str(err)) + except ErtCliError as err: + logger.debug(str(err)) sys.exit(str(err)) except ConfigValidationError as err: err_msg = err.cli_message() - logger.exception(err_msg) + logger.debug(err_msg) sys.exit(err_msg) except BaseException as err: logger.exception(f'ERT crashed unexpectedly with "{err}"') diff --git a/src/ert/cli/main.py b/src/ert/cli/main.py index 97f809e8dd7..36d2bc1f625 100644 --- a/src/ert/cli/main.py +++ b/src/ert/cli/main.py @@ -34,10 +34,6 @@ class ErtCliError(Exception): pass -class ErtTimeoutError(Exception): - pass - - def run_cli(args: Namespace, plugin_manager: Optional[ErtPluginManager] = None) -> None: ert_dir = os.path.abspath(os.path.dirname(args.config)) os.chdir(ert_dir) diff --git a/src/ert/gui/tools/plot/plot_window.py b/src/ert/gui/tools/plot/plot_window.py index 50b1fd27959..777129ad5a5 100644 --- a/src/ert/gui/tools/plot/plot_window.py +++ b/src/ert/gui/tools/plot/plot_window.py @@ -106,7 +106,7 @@ def __init__(self, config_file: str, parent: Optional[QWidget]): self._api = PlotApi() self._key_definitions = self._api.all_data_type_keys() except (RequestError, TimeoutError) as e: - logger.exception(e) + logger.exception(f"plot api request failed: {e}") open_error_dialog("Request failed", str(e)) self._key_definitions = [] QApplication.restoreOverrideCursor() @@ -191,7 +191,7 @@ def updatePlot(self, layer: Optional[int] = None) -> None: ensemble.id, key ) except (RequestError, TimeoutError) as e: - logger.exception(e) + logger.exception(f"plot api request failed: {e}") open_error_dialog("Request failed", f"{e}") observations = None @@ -201,7 +201,7 @@ def updatePlot(self, layer: Optional[int] = None) -> None: [ensembles.id for ensembles in selected_ensembles], key ) except (RequestError, TimeoutError) as e: - logger.exception(e) + logger.exception(f"plot api request failed: {e}") open_error_dialog("Request failed", f"{e}") std_dev_images: Dict[str, npt.NDArray[np.float32]] = {} @@ -221,7 +221,7 @@ def updatePlot(self, layer: Optional[int] = None) -> None: key, ensemble.id, layer ) except (RequestError, TimeoutError) as e: - logger.exception(e) + logger.exception(f"plot api request failed: {e}") open_error_dialog("Request failed", f"{e}") else: plot_widget.showLayerWidget.emit(False) @@ -241,7 +241,7 @@ def updatePlot(self, layer: Optional[int] = None) -> None: ) except (RequestError, TimeoutError) as e: - logger.exception(e) + logger.exception(f"plot api request failed: {e}") open_error_dialog("Request failed", f"{e}") plot_context.history_data = None