Skip to content

Commit

Permalink
Fix: capture all optlang exceptions (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-code-magician authored and Midnighter committed Feb 6, 2018
1 parent 023e48c commit a59af46
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cobra/util/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit a59af46

Please sign in to comment.