Commit c84fea0ea2677890e703e311095df01faed61953

Authored by Miguel Barão
1 parent 977fa070
Exists in master and in 1 other branch dev

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,12 +376,7 @@ class LearnApp(object):
376 for tref, attr in topics.items(): 376 for tref, attr in topics.items():
377 logger.debug(f' + {tref}') 377 logger.debug(f' + {tref}')
378 for d in attr.get('deps', []): 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 t = g.nodes[tref] # get current topic node 381 t = g.nodes[tref] # get current topic node
387 t['name'] = attr.get('name', tref) 382 t['name'] = attr.get('name', tref)
@@ -409,14 +404,20 @@ class LearnApp(object): @@ -409,14 +404,20 @@ class LearnApp(object):
409 404
410 # load questions as list of dicts 405 # load questions as list of dicts
411 topicpath: str = path.join(g.graph['prefix'], tref) 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 logger.debug(f' Loading {fullpath}') 414 logger.debug(f' Loading {fullpath}')
415 - # questions: List[QDict] = load_yaml(fullpath, default=[])  
416 try: 415 try:
417 questions: List[QDict] = load_yaml(fullpath) 416 questions: List[QDict] = load_yaml(fullpath)
418 except Exception: 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 if not isinstance(questions, list): 422 if not isinstance(questions, list):
422 msg = f'File "{fullpath}" must be a list of questions' 423 msg = f'File "{fullpath}" must be a list of questions'