From 339c9323455f4a52f49965d93bd6341fd5e0a81d Mon Sep 17 00:00:00 2001 From: belthlemar Date: Thu, 4 Jan 2024 10:32:15 +0100 Subject: [PATCH] feat(bc): add new exception for incoherent matrix --- antarest/core/exceptions.py | 5 +++++ antarest/study/business/binding_constraint_management.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/antarest/core/exceptions.py b/antarest/core/exceptions.py index 3414d6477b..2c91fecde3 100644 --- a/antarest/core/exceptions.py +++ b/antarest/core/exceptions.py @@ -199,6 +199,11 @@ def __init__(self, message: str) -> None: super().__init__(HTTPStatus.BAD_REQUEST, message) +class IncoherentConstraintMatrixTerm(HTTPException): + def __init__(self, message: str) -> None: + super().__init__(HTTPStatus.BAD_REQUEST, message) + + class MissingDataError(HTTPException): def __init__(self, message: str) -> None: super().__init__(HTTPStatus.NOT_FOUND, message) diff --git a/antarest/study/business/binding_constraint_management.py b/antarest/study/business/binding_constraint_management.py index ed3657aec3..c36f3b0f8f 100644 --- a/antarest/study/business/binding_constraint_management.py +++ b/antarest/study/business/binding_constraint_management.py @@ -6,6 +6,7 @@ ConstraintAlreadyExistError, ConstraintIdNotFoundError, DuplicateConstraintName, + IncoherentConstraintMatrixTerm, InvalidConstraintName, MissingDataError, NoBindingConstraintError, @@ -191,9 +192,11 @@ def create_binding_constraint( if int(study.version) >= 870: if data.values is not None: - raise ValueError("You cannot fill 'values' as it refers to the matrix before v8.7") + raise IncoherentConstraintMatrixTerm("You cannot fill 'values' as it refers to the matrix before v8.7") elif any([data.equal_term_matrix, data.less_term_matrix, data.greater_term_matrix]): - raise ValueError("You cannot fill a 'matrix_term' as these values refer to v8.7+ studies") + raise IncoherentConstraintMatrixTerm( + "You cannot fill a 'matrix_term' as these values refer to v8.7+ studies" + ) command = CreateBindingConstraint( name=data.name,