Log exceptions from CLI in log file
import datetime
import argparse
import os
+import traceback
import yaml
from kge import Dataset
@@ -222,6 +223,8 @@ def main():
else:
config.folder = args.folder
+ # catch errors to log them
+ try:
if args.command == "start" and not config.init_folder():
raise ValueError("output folder {} exists already".format(config.folder))
config.log("Using folder: {}".format(config.folder))
@@ -273,7 +276,10 @@ def main():
if args.command == "resume":
job.resume(checkpoint_file)
job.run()
-
+ except BaseException as e:
+ tb = traceback.format_exc()
+ config.log(tb, echo=False)
+ raise e from None
if __name__ == "__main__":
main()
