From 51e6dab8f251f42f9bfd147a82648ed60855d233 Mon Sep 17 00:00:00 2001 From: lrennels Date: Mon, 13 Jul 2020 20:13:14 -0700 Subject: [PATCH 1/5] Change deprecation warning to error for sim instance access methods --- src/mcs/mcs_types.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcs/mcs_types.jl b/src/mcs/mcs_types.jl index 2e39e95ea..18cf532ce 100644 --- a/src/mcs/mcs_types.jl +++ b/src/mcs/mcs_types.jl @@ -231,6 +231,6 @@ end function Base.getindex(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbol; model::Int = 1) msg = "getindex method for `SimulationInstance` has been replaced with getdataframe function for consistency of return type, please use getdataframe instead" - Base.depwarn("$msg, $(stacktrace())", :getindex) + error("$msg, $(stacktrace())", :getindex) return sim_inst.results[model][(comp_name, datum_name)] end From 6ac2128fe7579ad9bee1d849ec74201b9e98c397 Mon Sep 17 00:00:00 2001 From: Lisa Rennels <31779240+lrennels@users.noreply.github.com> Date: Mon, 13 Jul 2020 20:24:08 -0700 Subject: [PATCH 2/5] Fix error for SimulationInstance getindex --- src/mcs/mcs_types.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcs/mcs_types.jl b/src/mcs/mcs_types.jl index 18cf532ce..5b59ac7cf 100644 --- a/src/mcs/mcs_types.jl +++ b/src/mcs/mcs_types.jl @@ -231,6 +231,6 @@ end function Base.getindex(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbol; model::Int = 1) msg = "getindex method for `SimulationInstance` has been replaced with getdataframe function for consistency of return type, please use getdataframe instead" - error("$msg, $(stacktrace())", :getindex) + error("$msg, $(stacktrace())") return sim_inst.results[model][(comp_name, datum_name)] end From a98e81c298364c72e091616ccaf81bdb48200da0 Mon Sep 17 00:00:00 2001 From: lrennels Date: Mon, 13 Jul 2020 21:29:06 -0700 Subject: [PATCH 3/5] Fix error message --- src/mcs/mcs_types.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mcs/mcs_types.jl b/src/mcs/mcs_types.jl index 5b59ac7cf..8bce63027 100644 --- a/src/mcs/mcs_types.jl +++ b/src/mcs/mcs_types.jl @@ -231,6 +231,5 @@ end function Base.getindex(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbol; model::Int = 1) msg = "getindex method for `SimulationInstance` has been replaced with getdataframe function for consistency of return type, please use getdataframe instead" - error("$msg, $(stacktrace())") - return sim_inst.results[model][(comp_name, datum_name)] + error("$msg") end From 6fb70892dc0061e506407b1111d0006b6038899a Mon Sep 17 00:00:00 2001 From: lrennels Date: Wed, 15 Jul 2020 11:29:18 -0700 Subject: [PATCH 4/5] Improve error messages --- src/core/defcomp.jl | 2 +- src/core/model.jl | 10 ++-------- src/core/time.jl | 4 ++-- src/core/time_arrays.jl | 24 ++---------------------- src/mcs/mcs_types.jl | 3 +-- 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/core/defcomp.jl b/src/core/defcomp.jl index 2c6edbad3..9fde15773 100644 --- a/src/core/defcomp.jl +++ b/src/core/defcomp.jl @@ -198,7 +198,7 @@ macro defcomp(comp_name, ex) # DEPRECATION - EVENTUALLY REMOVE if @capture(elt, name_::datum_type_ = elt_type_(args__)) msg = "The following syntax has been deprecated in @defcomp: \"$name::$datum_type = $elt_type(...)\". Use curly bracket syntax instead: \"$name = $elt_type{$datum_type}(...)\"" - error("$msg\n$(reduce((x,y) -> "$x\n$y", stacktrace()))") + error("$msg\n$(reduce((x,y) -> "$x\n$y")") elseif ! @capture(elt, name_ = (elt_type_{datum_type_}(args__) | elt_type_(args__))) end diff --git a/src/core/model.jl b/src/core/model.jl index 1b9359fb8..a79e23497 100644 --- a/src/core/model.jl +++ b/src/core/model.jl @@ -171,10 +171,7 @@ new component specified by `comp_id`. Use the following syntax instead: See docstring for `replace!` for further description of available functionality. """ function replace_comp!(m::Model, comp_id::ComponentId, comp_name::Symbol=comp_id.comp_name; kwargs...) - msg = "Function `replace_comp!(m, comp_id, comp_name; kwargs...)` has been deprecated. Use `replace!(m, comp_name => Mimi.compdef(comp_id); kwargs...)` instead." - st = _get_stacktrace_string() - full_msg = string(msg, " \n", st) - error(full_msg) + error("Function `replace_comp!(m, comp_id, comp_name; kwargs...)` has been deprecated. Use `replace!(m, comp_name => Mimi.compdef(comp_id); kwargs...)` instead.") end # DEPRECATION - EVENTUALLY REMOVE @@ -194,10 +191,7 @@ new component specified by `comp_def`. Use the following syntax instead: See docstring for `replace!` for further description of available functionality. """ function replace_comp!(m::Model, comp_def::ComponentDef, comp_name::Symbol=comp_def.comp_id.comp_name; kwargs...) - msg = "Function `replace_comp!(m, comp_def, comp_name; kwargs...)` has been deprecated. Use `replace!(m, comp_name => comp_def; kwargs...)` instead." - st = _get_stacktrace_string() - full_msg = string(msg, " \n", st) - error(full_msg) + error("Function `replace_comp!(m, comp_def, comp_name; kwargs...)` has been deprecated. Use `replace!(m, comp_name => comp_def; kwargs...)` instead.") end """ diff --git a/src/core/time.jl b/src/core/time.jl index 6689a441c..2704d13d1 100644 --- a/src/core/time.jl +++ b/src/core/time.jl @@ -27,7 +27,7 @@ end Deprecated fucntion to return true or false, true if the current time (year) for `ts` is `t` """ function is_time(ts::AbstractTimestep, t::Int) - error("`is_time(ts, t)` is deprecated. Use comparison operators with TimestepValue objects instead: `ts == TimestepValue(t)` \n$(stacktrace())", :is_time) + error("`is_time(ts, t)` is deprecated. Use comparison operators with TimestepValue objects instead: `ts == TimestepValue(t)`") end """ @@ -46,7 +46,7 @@ end Deprecated function to return true or false, true if `ts` timestep is step `t`. """ function is_timestep(ts::AbstractTimestep, t::Int) - error("`is_timestep(ts, t)` is deprecated. Use comparison operators with TimestepIndex objects instead: `ts == TimestepIndex(t)` \n$(stacktrace())", :is_timestep) + error("`is_timestep(ts, t)` is deprecated. Use comparison operators with TimestepIndex objects instead: `ts == TimestepIndex(t)`") end """ diff --git a/src/core/time_arrays.jl b/src/core/time_arrays.jl index 9e611924e..a96272f51 100644 --- a/src/core/time_arrays.jl +++ b/src/core/time_arrays.jl @@ -57,36 +57,16 @@ function _single_index_check(data, idxs) end end -# DEPRECATION - EVENTUALLY REMOVE -# Helper to print stacktrace for the integer indexing errors -function _get_stacktrace_string() - s = "" - for line in stacktrace() - if startswith(string(line), "run_timestep") - return s - else - s = string(s, line, "\n") - end - end - return s -end - # DEPRECATION - EVENTUALLY REMOVE # Helper function for getindex; throws an error if one indexes into a TimestepArray with an integer function _throw_int_getindex_error() - msg = "Indexing with getindex into a TimestepArray with Integer(s) is deprecated, please index with a TimestepIndex(index::Int) instead ie. instead of t[2] use t[TimestepIndex(2)]\n" - st = _get_stacktrace_string() - full_msg = string(msg, " \n", st) - error(full_msg) + error("Indexing with getindex into a TimestepArray with Integer(s) is deprecated, please index with a TimestepIndex(index::Int) instead ie. instead of t[2] use t[TimestepIndex(2)]") end # DEPRECATION - EVENTUALLY REMOVE # Helper function for setindex; throws an error if one indexes into a TimestepArray with an integer function _throw_int_setindex_error() - msg = "Indexing with setindex into a TimestepArray with Integer(s) is deprecated, please index with a TimestepIndex(index::Int) instead ie. instead of t[2] use t[TimestepIndex(2)]" - st = _get_stacktrace_string() - full_msg = string(msg, " \n", st) - error(full_msg) + error("Indexing with setindex into a TimestepArray with Integer(s) is deprecated, please index with a TimestepIndex(index::Int) instead ie. instead of t[2] use t[TimestepIndex(2)]") end # Helper macro used by connector diff --git a/src/mcs/mcs_types.jl b/src/mcs/mcs_types.jl index 8bce63027..5fddbdb4b 100644 --- a/src/mcs/mcs_types.jl +++ b/src/mcs/mcs_types.jl @@ -230,6 +230,5 @@ function getdataframe(sim_inst::SimulationInstance, comp_name::Symbol, datum_nam end function Base.getindex(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbol; model::Int = 1) - msg = "getindex method for `SimulationInstance` has been replaced with getdataframe function for consistency of return type, please use getdataframe instead" - error("$msg") + error("getindex method for `SimulationInstance` has been replaced with getdataframe function for consistency of return type, please use getdataframe instead") end From 7c84f071189fae2db2ded9cd4347cc2f374aef2c Mon Sep 17 00:00:00 2001 From: lrennels Date: Wed, 15 Jul 2020 11:48:37 -0700 Subject: [PATCH 5/5] Fix defcomp error message bug --- src/core/defcomp.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/defcomp.jl b/src/core/defcomp.jl index 9fde15773..2b527d0fe 100644 --- a/src/core/defcomp.jl +++ b/src/core/defcomp.jl @@ -197,8 +197,7 @@ macro defcomp(comp_name, ex) # DEPRECATION - EVENTUALLY REMOVE if @capture(elt, name_::datum_type_ = elt_type_(args__)) - msg = "The following syntax has been deprecated in @defcomp: \"$name::$datum_type = $elt_type(...)\". Use curly bracket syntax instead: \"$name = $elt_type{$datum_type}(...)\"" - error("$msg\n$(reduce((x,y) -> "$x\n$y")") + error("The following syntax has been deprecated in @defcomp: \"$name::$datum_type = $elt_type(...)\". Use curly bracket syntax instead: \"$name = $elt_type{$datum_type}(...)\"") elseif ! @capture(elt, name_ = (elt_type_{datum_type_}(args__) | elt_type_(args__))) end