From 81a5c737d02ea474b23b32c97903eefba8de478a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Mon, 10 Oct 2022 18:50:53 +0200 Subject: [PATCH] Amelioration de la detection d'erreur lors du set situation --- .../source/components/utils/EngineContext.tsx | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/site/source/components/utils/EngineContext.tsx b/site/source/components/utils/EngineContext.tsx index 05c5e5db5..6faf5b05a 100644 --- a/site/source/components/utils/EngineContext.tsx +++ b/site/source/components/utils/EngineContext.tsx @@ -91,10 +91,7 @@ export const safeSetSituation = ( err.message === (error as Error).message ) ) { - engine.setSituation({}) - onError({ situation: {} }) - - break + throw error } errors.push(error as Error) @@ -128,12 +125,37 @@ export const useSetupSafeSituation = (engine: Engine) => { const dispatch = useDispatch() const rawSituation = useRawSituation() - safeSetSituation( - engine, - rawSituation, - ({ faultyDottedName }) => - faultyDottedName && dispatch(deleteFromSituation(faultyDottedName)) - ) + const simulatorSituation = useSelector(situationSelector) + const configSituation = useSelector(configSituationSelector) + const companySituation = useSelector(companySituationSelector) + + try { + safeSetSituation(engine, rawSituation, ({ faultyDottedName }) => { + if (!faultyDottedName) { + throw new Error('Bad empty faultyDottedName') + } + + if (faultyDottedName in simulatorSituation) { + dispatch(deleteFromSituation(faultyDottedName)) + } else { + throw new Error( + 'Bad ' + + (faultyDottedName in configSituation + ? 'config' + : faultyDottedName in companySituation + ? 'company' + : 'unknow') + + ' situation : ' + + JSON.stringify(faultyDottedName) + ) + } + }) + } catch (error) { + // eslint-disable-next-line no-console + console.error(error) + + engine.setSituation() + } } export function useInversionFail() {