-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle errors and warns #118
Conversation
change all instances of @error to error()
Note for reviewer: Graceful exist is only implemented on |
Add error key to report in case of failures.
for wholesale rates and fuel cost mmbtu.
Thinking about how this can be implemented in the API, should we simplify the Messages dictionary to just be for |
I think avoiding nested dicts is a good idea. I'd be fine with either combining both into a Messages dict (with each message either pre-pended by "Warning:" or "Error:") or separating them out. We definitely want to report back errors though! |
One thought, open to debate, is to always have the same keys in the response dictionary, and if there are e.g. no errors, the value/object in the Error key is null. We have a conditional dictionary key within messages for errors in the current API response, and I think that it makes it harder to parse. |
@rathod-b could you update the changelog and description of this PR? |
I agree with prior comments, and will update the output so we always have a |
And create function to gracefully handle errors in REopt
Hi @Bill-Becker @adfarth do you guys see any issues with the following return format for Warnings and Errors:
Here is the output for a graceful error. I've kept the same format for now. I hope its okay to include the entire stacktrace? |
and update changelog
@rathod-b can you merge this if it's all set, or call out any remaining items to be addressed? |
Rm commented out JSON from file
@Bill-Becker I have resolved all but 2 comments where I wasnt sure what the next step should be. One in src/core/heating_cooling_loads.jl and the other in src/core/existing_boiler.jl. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have any comments to address here (I was only referenced in a comment), so I'll append my approval to that of @Bill-Becker
Include try/catches for run_reopt() functions which are most likely to be called by the API, validated functionality with API using end-to-end testing.
@test length(r["Messages"]["errors"]) > 0 | ||
@test length(r["Messages"]["warnings"]) > 0 | ||
|
||
# Throw an unhandled error: Bad URDB rate -> stack gets returned for debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious if it's really necessary to test all 4 run_reopt() versions (1 and 2 models, file path and dict) here again if you already did that above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its okay to have these tests. Mainly the first 4 tests are looking at invoking REopt.jl in 4 different ways and handling an error which REopt.jl already handles with throw(@error(...))
statement. The last 4 tests do the same thing as first, but the error generated now is an unhandled error where REopt is supposed to return the stack + error message. So these tests just try different ways to test that both iterations of handle_errors()
function are working as expected.
I didn't see any considerable impact on solve times since the scenarios are supposed to error out before they begin solving.
Rm extra logger instantiations in run_reopt(Model, Scenario).
a global loggerlogfile.log
src/logREopt.jl
(events with log level >= @ info printed to console.logREopt.d
logREopt.d
Added
logREopt
as the global logger in__init()__
function call as a global variablecore/reopt.jl -> run_reopt()
functions. Process any errors when catching the error.logREopt
to results dictionary. If error is unhandled in REopt, include a stacktracestatus
oferror
to results for consistencyhandle_errors(e::E, stacktrace::V) where {E <: Exception, V <: Vector}
andhandle_errors()
tocore/reopt.jl
to gracefully handle scenarios where REopt fails during data processing/optimizationChanged
core/reopt.jl
added try-catch statements to gracefully catch a REopt error and return it to user along with where the error happened.TODO:Changehandled by logREoptresults["messages"]
to Dict; add keys with related input, constraint, or result (e.g.PV input
orcore/pv.jl
) and list of strings with messages (e.g. ["Warning: 1", "Warning: 2"])handle_messages()
Make sure log file properly closes and that new logs overwrite old ones.NA since we are using a dictionary and global loggerCheck multiple runs on development server