-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add an error message when GADM server is down #890
Add an error message when GADM server is down #890
Conversation
A suggestion on how to make more clear that GADM server is down, when running the workflow. @davide-f may you please have a look? :) Error messages are duplicated to keep error message both in console and in logs. It could probably make sense to stop execution with something like |
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.
Nice draft :D few little comments! :)
scripts/build_shapes.py
Outdated
logger.error(f"GADM server is down at {GADM_url}") | ||
raise Exception(f"GADM server is down at {GADM_url}") |
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.
Having logger and raise is a bit annoying.
Could you try if logger.critical(.) or logger.exception(.) also trigger an exit of the execution?
I'd avoid the execution of "raise" because it still leads to dirty logging.
In the general exception tracker, the textual description of the exception str(exception)
may be added as well.
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.
Have played around logger, but there seems to be no way to stop execution just by logging tools :( As far as I was able to find, both logger.critical( )
and logger.exception( )
have a purely information function.
Agree that raise
doesn't look nice. But executing is anyway stopped when geopandas tries to read a non-existing file. So, probably we can just make an error message more clear. What do you think?
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.
An approach may be to use sys.exit() to close the execution forcefully.
Regarding the exception trace, I just realized that there is the option "exc_info=True" that may automatically log the trace.
Ok also as is now, it is is nicer in the log we could also take it into consideration.
What do you think?
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, implementation with exc_info=True
is definitely nicer :D Revised and ddded sys.exit(1)
, which seems to give much more clear logging output.
Thanks a lot!! :)) Added a next iteration :) |
@davide thanks a lot for reviewing! :) As a comment, I fear a currently implemented approach is not perfectly consistent with the rest of the code. Usually, we are rising exceptions to handle errors, for example: pypsa-earth/scripts/build_shapes.py Lines 577 to 580 in b205e83
Now we are testing |
Agree, nice catch! :) |
139ae5d
to
dfe0867
Compare
@davide-f thanks a lot for looking into logs for uncaught exceptions :) Have tried an implementation you referred, and I think the results is very nice! Snakemake error listing remains and is verbose as usual, while a cleaner output is added to a log file. An example of log output provoked by calling an undefined variable: ERROR:_helpers:An error happened during workflow execution.
Traceback (most recent call last):
File "/Users/ekaterina/Documents/_github_/pypsa-earth/.snakemake/scripts/tmpz3zieg8k.build_shapes.py", line 942, in <module>
print(x + y)
NameError: name 'x' is not defined I think, that may be exactly what we do need. What is your feeling about that? |
So, for this PR, I personally believe that simply using the raise instead of logging.error was enough, while the better handling of the exception could be done in a separate PR. I like the implementation, but I'd keep them separate to ease the revision too as the revision of the logger/exception handling should be done to all other scripts as well. To better handle the errors, I strongly like this draft. logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
sys.excepthook = handle_exception However, since implementing this requires changing all scripts, I'd keep for a separate PR, what do you think? |
3a67a8e
to
736ac39
Compare
Agree that it's better to keep it simple. Revised :) Have moved a part with the exceptions hook to #898 |
Changes proposed in this Pull Request
Add an error message for a case when GADM server is down.
Checklist
envs/environment.yaml
anddoc/requirements.txt
.config.default.yaml
andconfig.tutorial.yaml
.test/
(note tests are changing the config.tutorial.yaml)doc/configtables/*.csv
and line references are adjusted indoc/configuration.rst
anddoc/tutorial.rst
.doc/release_notes.rst
is amended in the format of previous release notes, including reference to the requested PR.