From 4566817094f7847b3e97a276879b099af5975d21 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 23 Jan 2023 19:03:20 -0300 Subject: [PATCH] critical errors handler (xp) --- app/__init__.py | 19 +++++++++++++++++++ app/comp/moy_mod.py | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 6fb6cf052..5217736fc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -550,3 +550,22 @@ def scodoc_flash_status_messages(): f"Mode test: mails redirigés vers {email_test_mode_address}", category="warning", ) + + +def critical_error(msg): + """Handle a critical error: flush all caches, display message to the user""" + import app.scodoc.sco_utils as scu + + log(f"\n*** CRITICAL ERROR: {msg}") + send_scodoc_alarm(f"CRITICAL ERROR: {msg}", msg) + clear_scodoc_cache() + raise ScoValueError( + f""" + Une erreur est survenue. + + Si le problème persiste, merci de contacter le support ScoDoc via + {scu.SCO_DISCORD_ASSISTANCE} + + {msg} + """ + ) diff --git a/app/comp/moy_mod.py b/app/comp/moy_mod.py index dfced34cc..1fccbda15 100644 --- a/app/comp/moy_mod.py +++ b/app/comp/moy_mod.py @@ -39,6 +39,7 @@ from dataclasses import dataclass import numpy as np import pandas as pd +import app from app import db from app.models import Evaluation, EvaluationUEPoids, ModuleImpl from app.scodoc import sco_cache @@ -484,7 +485,8 @@ class ModuleImplResultsClassic(ModuleImplResults): if nb_etuds == 0: return pd.Series() evals_coefs = self.get_evaluations_coefs(modimpl).reshape(-1) - assert evals_coefs.shape == (nb_evals,) + if evals_coefs.shape != (nb_evals,): + app.critical_error("compute_module_moy: vals_coefs.shape != nb_evals") evals_notes_20 = self.get_eval_notes_sur_20(modimpl) # Les coefs des évals pour chaque étudiant: là où il a des notes # non neutralisées