diff --git a/src/solver/model_getters.jl b/src/solver/model_getters.jl index 2655e70c17..ff2a4a0b81 100644 --- a/src/solver/model_getters.jl +++ b/src/solver/model_getters.jl @@ -12,7 +12,17 @@ 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" 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