From fb1485a540a27bc7f35cc9f46a2aa6ff85a81410 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sat, 8 Jul 2023 21:21:07 +0200 Subject: [PATCH] ENH: warn instead of raise violated rules (#224) * ENH: pass execution info through `RuntimeError` --- src/qrules/transition.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qrules/transition.py b/src/qrules/transition.py index 3ec4db68..f33f5fc0 100644 --- a/src/qrules/transition.py +++ b/src/qrules/transition.py @@ -2,6 +2,7 @@ import logging import re +import warnings from collections import abc, defaultdict from copy import copy, deepcopy from enum import Enum, auto @@ -613,10 +614,11 @@ def find_solutions( # noqa: C901, PLR0912 for rules in execution_info.violated_node_rules.values(): violated_rules |= rules if violated_rules: - raise RuntimeError( + msg = ( "There were violated conservation rules: " - + ", ".join(violated_rules) + f" {', '.join(violated_rules)}" ) + warnings.warn(msg, category=RuntimeWarning, stacklevel=1) if ( final_result.execution_info.not_executed_edge_rules or final_result.execution_info.not_executed_node_rules @@ -626,13 +628,14 @@ def find_solutions( # noqa: C901, PLR0912 not_executed_rules |= rules for rules in execution_info.not_executed_node_rules.values(): not_executed_rules |= rules - raise RuntimeWarning( - "There are conservation rules that were not executed: " - + ", ".join(not_executed_rules) + msg = ( + "There are conservation rules that were not executed:" + f" {', '.join(not_executed_rules)}" ) + warnings.warn(msg, category=RuntimeWarning, stacklevel=1) if not final_solutions: msg = "No solutions were found" - raise ValueError(msg) + raise RuntimeError(msg, execution_info) match_external_edges(final_solutions) final_solutions = [