Commit a881e511fe5216efe75cf46ac70284ca8b4b1853
1 parent
1d65b0b7
Exists in
master
and in
1 other branch
- missing database aborts cleanly instead of exception.
- main added to the loggers (todo: change logging to logger)
Showing
2 changed files
with
11 additions
and
12 deletions
Show diff stats
aprendizations/learnapp.py
| ... | ... | @@ -373,12 +373,12 @@ class LearnApp(): |
| 373 | 373 | |
| 374 | 374 | logger.info('Checking database "%s":', database) |
| 375 | 375 | if not exists(database): |
| 376 | - raise LearnException('Database does not exist. ' | |
| 377 | - 'Use "initdb-aprendizations" to create') | |
| 376 | + msg = 'Database does not exist.' | |
| 377 | + logger.error(msg) | |
| 378 | + raise LearnException(msg) | |
| 378 | 379 | |
| 379 | 380 | self._engine = create_engine(f'sqlite:///{database}', future=True) |
| 380 | 381 | |
| 381 | - | |
| 382 | 382 | try: |
| 383 | 383 | query_students = select(func.count(Student.id)) |
| 384 | 384 | query_topics = select(func.count(Topic.id)) | ... | ... |
aprendizations/main.py
| ... | ... | @@ -7,6 +7,7 @@ Setup configurations and then runs the application. |
| 7 | 7 | |
| 8 | 8 | # python standard library |
| 9 | 9 | import argparse |
| 10 | +import logging | |
| 10 | 11 | import logging.config |
| 11 | 12 | from os import environ, path |
| 12 | 13 | import ssl |
| ... | ... | @@ -14,10 +15,10 @@ import sys |
| 14 | 15 | from typing import Any, Dict |
| 15 | 16 | |
| 16 | 17 | # this project |
| 17 | -from aprendizations.learnapp import LearnApp, DatabaseUnusableError, LearnException | |
| 18 | -from aprendizations.serve import run_webserver | |
| 19 | -from aprendizations.tools import load_yaml | |
| 20 | -from aprendizations import APP_NAME, APP_VERSION | |
| 18 | +from .learnapp import LearnApp, DatabaseUnusableError, LearnException | |
| 19 | +from .serve import run_webserver | |
| 20 | +from .tools import load_yaml | |
| 21 | +from . import APP_NAME, APP_VERSION | |
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | # ---------------------------------------------------------------------------- |
| ... | ... | @@ -115,7 +116,7 @@ def get_logger_config(debug: bool = False) -> Any: |
| 115 | 116 | 'level': level, |
| 116 | 117 | 'propagate': False, |
| 117 | 118 | } for module in ['learnapp', 'models', 'factory', 'tools', 'serve', |
| 118 | - 'questions', 'student']}) | |
| 119 | + 'questions', 'student', 'main']}) | |
| 119 | 120 | |
| 120 | 121 | return load_yaml(config_file, default=default_config) |
| 121 | 122 | |
| ... | ... | @@ -197,12 +198,10 @@ def main(): |
| 197 | 198 | sys.exit(1) |
| 198 | 199 | except LearnException as exc: |
| 199 | 200 | logging.critical('Failed to start backend') |
| 200 | - # sys.exit(1) | |
| 201 | - raise | |
| 201 | + sys.exit(1) | |
| 202 | 202 | except Exception: |
| 203 | 203 | logging.critical('Unknown error') |
| 204 | - # sys.exit(1) | |
| 205 | - raise | |
| 204 | + sys.exit(1) | |
| 206 | 205 | else: |
| 207 | 206 | logging.info('LearnApp started') |
| 208 | 207 | ... | ... |