From a59af468824b9b178fee409df4d4c69fd83d4fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gon=C3=A7alo=20Rocha=20Cardoso?= Date: Tue, 6 Feb 2018 11:58:33 +0100 Subject: [PATCH] Fix: capture all optlang exceptions (#665) --- cobra/util/solver.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cobra/util/solver.py b/cobra/util/solver.py index 1370e803d..4d50ed412 100644 --- a/cobra/util/solver.py +++ b/cobra/util/solver.py @@ -421,5 +421,8 @@ def assert_optimal(model, message='optimization failed'): message : str (optional) Message to for the exception if solver status was not optimal. """ - if model.solver.status != optlang.interface.OPTIMAL: - raise OPTLANG_TO_EXCEPTIONS_DICT[model.solver.status](message) + status = model.solver.status + if status != optlang.interface.OPTIMAL: + exception_cls = OPTLANG_TO_EXCEPTIONS_DICT.get( + status, OptimizationError) + raise exception_cls("{} ({})".format(message, status))