From 0ec3f026945238adad3b4f30a84e8fd71ef8935f Mon Sep 17 00:00:00 2001 From: James Tomlinson Date: Thu, 15 Aug 2024 16:26:34 +0100 Subject: [PATCH] feat: Include the parameters names CircularParameterReference error. --- pywr-schema/src/error.rs | 7 ++++--- pywr-schema/src/model.rs | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pywr-schema/src/error.rs b/pywr-schema/src/error.rs index 530796ef..586b7bf9 100644 --- a/pywr-schema/src/error.rs +++ b/pywr-schema/src/error.rs @@ -30,8 +30,8 @@ pub enum SchemaError { DataTable(#[from] TableError), #[error("Circular node reference(s) found.")] CircularNodeReference, - #[error("Circular parameters reference(s) found.")] - CircularParameterReference, + #[error("Circular parameters reference(s) found. Unable to load the following parameters: {0:?}")] + CircularParameterReference(Vec), #[error("unsupported file format")] UnsupportedFileFormat, #[error("Python error: {0}")] @@ -56,7 +56,8 @@ pub enum SchemaError { LoadParameter { name: String, error: String }, #[error("Timeseries error: {0}")] Timeseries(#[from] TimeseriesError), - #[error("The output of literal constant values is not supported. This is because they do not have a unique identifier such as a name. If you would like to output a constant value please use a `Constant` parameter.")] + #[error("The output of literal constant values is not supported. This is because they do not have a unique identifier such as a name. If you would like to output a constant value please use a `Constant` parameter." + )] LiteralConstantOutputNotSupported, #[error("Chrono out of range error: {0}")] OutOfRange(#[from] chrono::OutOfRange), diff --git a/pywr-schema/src/model.rs b/pywr-schema/src/model.rs index 39f0a60e..a278c1a0 100644 --- a/pywr-schema/src/model.rs +++ b/pywr-schema/src/model.rs @@ -491,7 +491,8 @@ impl PywrNetwork { if failed_parameters.len() == n { // Could not load any parameters; must be a circular reference - return Err(SchemaError::CircularParameterReference); + let failed_names = failed_parameters.iter().map(|p| p.name().to_string()).collect(); + return Err(SchemaError::CircularParameterReference(failed_names)); } remaining_parameters = failed_parameters;