From 50fd1e7b2e05e1670b97e747849bb30a2d2f5732 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Tue, 26 Mar 2024 19:24:55 -0700 Subject: [PATCH 1/5] Throw a more informative error for unsupported config entries --- src/solver/yaml_helper.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/solver/yaml_helper.jl b/src/solver/yaml_helper.jl index 00c980dea4..8cc41f5597 100644 --- a/src/solver/yaml_helper.jl +++ b/src/solver/yaml_helper.jl @@ -72,7 +72,17 @@ function override_default_config(config_dict::AbstractDict;) for k in intersect(keys(config_dict), keys(default_config)) default_type = typeof(default_config[k]) v = config_dict[k] - config[k] = isnothing(default_config[k]) ? v : default_type(v) + + # Attempt to convert user value `v` to the same type as + # the default. If that fails, throw an informative error. + config[k] = try + isnothing(default_config[k]) ? v : default_type(v) + catch err + user_entry_type = typeof(v) + msg = """Configuration entry "$(k)" = $v has type $(user_entry_type), + but must have type $default_type.""" + throw(ArgumentError(msg)) + end end # The "diagnostics" entry is a more complex type that doesn't fit the schema described in From 1cf9401d8d6ba77baec45bc623912248a5dd87f5 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 28 Mar 2024 10:44:37 -0700 Subject: [PATCH 2/5] Improve assertion error for invalid configuration types --- src/solver/model_getters.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index 6a36fd4219..eaf0b8dbd1 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -12,7 +12,15 @@ end function get_model_config(parsed_args) config = parsed_args["config"] - @assert config in ("sphere", "column", "box", "plane") + + valid_configurations = ("sphere", "column", "box", "plane") + + if !(config ∈ valid_configurations) + error_message = string("config = $config is not one of the", + "valid configurations $valid_configurations") + throw(ArgumentError(error_message)) + end + return if config == "sphere" SphericalModel() elseif config == "column" From 66bdf9fc29d5fd5cafed43214d80439d8c37d3dc Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 28 Mar 2024 10:47:35 -0700 Subject: [PATCH 3/5] Add a space for correct spelling --- src/solver/model_getters.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index eaf0b8dbd1..322a6e86f9 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -16,7 +16,7 @@ function get_model_config(parsed_args) valid_configurations = ("sphere", "column", "box", "plane") if !(config ∈ valid_configurations) - error_message = string("config = $config is not one of the", + error_message = string("config = $config is not one of the ", "valid configurations $valid_configurations") throw(ArgumentError(error_message)) end From ee0ea832c2bbd973df91b59327a7aba7e635e186 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 28 Mar 2024 10:56:09 -0700 Subject: [PATCH 4/5] Try to please the formatter because it is my master and I am nothing --- src/solver/model_getters.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index 322a6e86f9..03b1a01bd1 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -16,8 +16,10 @@ function get_model_config(parsed_args) valid_configurations = ("sphere", "column", "box", "plane") if !(config ∈ valid_configurations) - error_message = string("config = $config is not one of the ", - "valid configurations $valid_configurations") + error_message = string( + "config = $config is not one of the ", + "valid configurations $valid_configurations" + ) throw(ArgumentError(error_message)) end From 95ae36e096838f75cc000a28f97d0450f0cb6f5d Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 28 Mar 2024 10:59:12 -0700 Subject: [PATCH 5/5] Yes master formatter I apologize for my grave transgressions --- src/solver/model_getters.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index 03b1a01bd1..5789aad2bf 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -18,7 +18,7 @@ function get_model_config(parsed_args) if !(config ∈ valid_configurations) error_message = string( "config = $config is not one of the ", - "valid configurations $valid_configurations" + "valid configurations $valid_configurations", ) throw(ArgumentError(error_message)) end