Skip to content

Commit

Permalink
feat: properly detect (deprecated) return values of addon functions (…
Browse files Browse the repository at this point in the history
…related to ait-energy#30)
  • Loading branch information
Stefan Strömer committed Nov 19, 2024
1 parent 22b5e91 commit fdbf4da
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/IESopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ function _build_model!(model::JuMP.Model)
# Only execute a function if it exists.
if addon_fi in names(prop.addon; all=true)
@info "Invoking addon" addon = name step = addon_fi
if !Base.invokelatest(getfield(prop.addon, addon_fi), model, prop.config)
ret = Base.invokelatest(getfield(prop.addon, addon_fi), model, prop.config)
if isnothing(ret)
@warn "Please make sure your addon returns `true` or `false` in every step to indicate success/failure" addon =
name step = addon_fi
elseif ret === false
@critical "Addon returned error" addon = name step = addon_fi
elseif ret !== true
@warn "Addon returned unexpected value: `$(ret)`" addon = name step = addon_fi
end
end
end
Expand Down

0 comments on commit fdbf4da

Please sign in to comment.