Commit c84fea0ea2677890e703e311095df01faed61953
1 parent
977fa070
Exists in
master
and in
1 other branch
fix error where dependencies could fail to load
Showing
1 changed file
with
10 additions
and
9 deletions
Show diff stats
aprendizations/learnapp.py
... | ... | @@ -376,12 +376,7 @@ class LearnApp(object): |
376 | 376 | for tref, attr in topics.items(): |
377 | 377 | logger.debug(f' + {tref}') |
378 | 378 | for d in attr.get('deps', []): |
379 | - if d not in g.nodes(): | |
380 | - logger.error(f'Topic "{tref}" depends on "{d}" but it ' | |
381 | - f'does not exist') | |
382 | - raise LearnException() | |
383 | - else: | |
384 | - g.add_edge(d, tref) | |
379 | + g.add_edge(d, tref) | |
385 | 380 | |
386 | 381 | t = g.nodes[tref] # get current topic node |
387 | 382 | t['name'] = attr.get('name', tref) |
... | ... | @@ -409,14 +404,20 @@ class LearnApp(object): |
409 | 404 | |
410 | 405 | # load questions as list of dicts |
411 | 406 | topicpath: str = path.join(g.graph['prefix'], tref) |
412 | - fullpath: str = path.join(topicpath, t['file']) | |
407 | + try: | |
408 | + fullpath: str = path.join(topicpath, t['file']) | |
409 | + except Exception: | |
410 | + msg1 = f'Invalid topic "{tref}"' | |
411 | + msg2 = f'Check dependencies of {", ".join(g.successors(tref))}' | |
412 | + raise LearnException(f'{msg1}. {msg2}') | |
413 | 413 | |
414 | 414 | logger.debug(f' Loading {fullpath}') |
415 | - # questions: List[QDict] = load_yaml(fullpath, default=[]) | |
416 | 415 | try: |
417 | 416 | questions: List[QDict] = load_yaml(fullpath) |
418 | 417 | except Exception: |
419 | - raise LearnException(f'Failed to load "{fullpath}"') | |
418 | + msg = f'Failed to load "{fullpath}"' | |
419 | + logger.error(msg) | |
420 | + raise LearnException(msg) | |
420 | 421 | |
421 | 422 | if not isinstance(questions, list): |
422 | 423 | msg = f'File "{fullpath}" must be a list of questions' | ... | ... |