Add Bot run with exception handling
Errors, especially caused by missing run-method, need to be catched to provide information in Logfile. And also to get information wether bot run was successfull Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=82 FS#82] Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=82 FS#82]
This commit is contained in:
43
red.py
43
red.py
@@ -34,7 +34,7 @@ from pywikibot import pagegenerators
|
|||||||
import jogobot
|
import jogobot
|
||||||
|
|
||||||
|
|
||||||
def main(*args):
|
def main(*args): # noqa (temp)
|
||||||
"""
|
"""
|
||||||
Process command line arguments and invoke bot.
|
Process command line arguments and invoke bot.
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ def main(*args):
|
|||||||
# It has to threw an exception if something does not work properly
|
# It has to threw an exception if something does not work properly
|
||||||
try:
|
try:
|
||||||
# Init bot with genFactory and **kwargs
|
# Init bot with genFactory and **kwargs
|
||||||
bot = Bot( genFactory, **kwargs ) # noqa (temp)
|
bot = Bot( genFactory, **kwargs )
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# Catch Errors while initiation
|
# Catch Errors while initiation
|
||||||
@@ -132,7 +132,44 @@ def main(*args):
|
|||||||
else:
|
else:
|
||||||
# Init successfull
|
# Init successfull
|
||||||
jogobot.output( (
|
jogobot.output( (
|
||||||
"{task_slug}-{subtask} init successfull" ).
|
"Subtask \"{task_slug}-{subtask}\" was" +
|
||||||
|
"initiated successfully" ).
|
||||||
|
format(task_slug=task_slug, subtask=subtask) )
|
||||||
|
|
||||||
|
# Fire up Bot
|
||||||
|
# Bot must have implemented a run()-method
|
||||||
|
# It has to threw an exception if something does not work properly
|
||||||
|
try:
|
||||||
|
# Call run method on Bot
|
||||||
|
bot.run()
|
||||||
|
|
||||||
|
# Special event on AttributeError to catch missing run()-method
|
||||||
|
except AttributeError:
|
||||||
|
(type, value, traceback) = sys.exc_info()
|
||||||
|
|
||||||
|
# Catch missing run()-method
|
||||||
|
if "has no attribute 'run'" in value:
|
||||||
|
jogobot.output( (
|
||||||
|
"\03{{red}} Error while trying to run " +
|
||||||
|
"subtask \"{task_slug}-{subtask} \": +"
|
||||||
|
"Run-method is missing! ").
|
||||||
|
format( task_slug=task_slug, subtask=subtask ), "ERROR" )
|
||||||
|
|
||||||
|
# Pass through other AttributeError
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
except:
|
||||||
|
jogobot.output( (
|
||||||
|
"\03{{red}} Error while trying to run " +
|
||||||
|
"subtask \"{task_slug}-{subtask} \"!" ).
|
||||||
|
format( task_slug=task_slug, subtask=subtask ), "ERROR" )
|
||||||
|
raise
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Run successfull
|
||||||
|
jogobot.output( (
|
||||||
|
"Subtask \"{task_slug}-{subtask}\" was finished successfully").
|
||||||
format(task_slug=task_slug, subtask=subtask) )
|
format(task_slug=task_slug, subtask=subtask) )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user