Skip to content

Commit

Permalink
fix: error message for compressor model in turbine
Browse files Browse the repository at this point in the history
Include the turbine name in the error message.

Refs: ECALC-1199
  • Loading branch information
jsolaas committed Jul 2, 2024
1 parent 28ba930 commit 8b57915
Showing 1 changed file with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,45 @@ def check_model_reference_wrapper(model_reference: Any, info: ValidationInfo):

models_context = info.context.get(YamlModelValidationContextNames.model_types)
try:
model_reference = check_model_reference(
model_reference,
available_models=models_context,
allowed_types=allowed_types,
)
try:
model_reference = check_model_reference(
model_reference,
available_models=models_context,
allowed_types=allowed_types,
)

except InvalidModelReferenceType as e:
raise PydanticCustomError(
"model_reference_type_invalid",
"Model '{model_reference}' with type {model_type} is not allowed",
{
"model_reference": e.model_reference,
"model_type": e.model.type,
},
) from e

# Also check compressor models in turbine
model = models_context[model_reference]
if model.type == YamlModelType.COMPRESSOR_WITH_TURBINE:
# Handle the compressor_model in turbine, it should be limited to the specified types.
check_model_reference(
model.compressor_model,
allowed_types=allowed_model_types,
available_models=models_context,
)
try:
check_model_reference(
model.compressor_model,
allowed_types=allowed_model_types,
available_models=models_context,
)

except InvalidModelReferenceType as e:
raise PydanticCustomError(
"model_reference_type_invalid",
"Turbine '{turbine_reference}' with compressor model '{model_reference}' of type {model_type} is not allowed",
{
"turbine_reference": model_reference,
"model_reference": e.model_reference,
"model_type": e.model.type,
},
) from e

except ModelReferenceNotFound as e:
raise PydanticCustomError(
"model_reference_not_found",
Expand All @@ -81,15 +107,6 @@ def check_model_reference_wrapper(model_reference: Any, info: ValidationInfo):
"model_reference": e.model_reference,
},
) from e
except InvalidModelReferenceType as e:
raise PydanticCustomError(
"model_reference_type_invalid",
"Model '{model_reference}' with type {model_type} is not allowed",
{
"model_reference": e.model_reference,
"model_type": e.model.type,
},
) from e

return check_model_reference_wrapper

Expand Down

0 comments on commit 8b57915

Please sign in to comment.