From d83c1754d11464117b21a569d6b995f1aa4e4296 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Fri, 31 Mar 2023 14:09:13 +0200
Subject: [PATCH] fix: MacroRugoRemous: return result error if
 setNubMacroRugoFromProps() fails

refs #325
---
 src/macrorugo/macrorugo_remous.ts | 44 +++++++++++++++++++------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/macrorugo/macrorugo_remous.ts b/src/macrorugo/macrorugo_remous.ts
index 45784c4a..56a0f34d 100644
--- a/src/macrorugo/macrorugo_remous.ts
+++ b/src/macrorugo/macrorugo_remous.ts
@@ -54,9 +54,11 @@ export class MacroRugoRemous extends CourbeRemous {
                 if (this._nubMacroRugo.result === undefined) {
                     this._nubMacroRugo.CalcSerie();
                 }
-                this._nubMacroRugo.calculatedParam.singleValue = this._nubMacroRugo.result.vCalc;
-                this._nubMacroRugo.calculatedParam = this._nubMacroRugo.prms.If;
-                this._nubMacroRugo.prms.Q.visible = false;
+                if (this._nubMacroRugo.result.ok) {
+                    this._nubMacroRugo.calculatedParam.singleValue = this._nubMacroRugo.result.vCalc;
+                    this._nubMacroRugo.calculatedParam = this._nubMacroRugo.prms.If;
+                    this._nubMacroRugo.prms.Q.visible = false;
+                }
             }
             // silent fail if (nub === undefined)
         }
@@ -70,21 +72,22 @@ export class MacroRugoRemous extends CourbeRemous {
      */
     public syncSectionMacroRugo() {
         this.setNubMacroRugoFromProps();
+        if (this._nubMacroRugo.result.ok) {
+            this.section.prms.LargeurBerge.singleValue = this._nubMacroRugo.prms.B.V;
+            this._nubMacroRugo.prms.Q.singleValue = this.section.prms.Q.singleValue;
+            this.section.prms.If.singleValue = this._nubMacroRugo.prms.If.v;
+            const Z2 = this.prms.Z2.singleValue;
+            const ZF2 = this._nubMacroRugo.result.getValue("ZF2");
+            this.section.prms.YB.singleValue = Math.max((Z2 - ZF2) * 1.5, 1); // pour éviter de fournir Infinity (max avec 1 à cause des fuzz tests)
+            this.section.prms.Ks.singleValue = this._nubMacroRugo.result.resultElement.values.Strickler;
+            this.prms.ZF1.singleValue = this._nubMacroRugo.prms.ZF1.singleValue;
+            this.prms.ZF2.singleValue = ZF2;
+            this.prms.Long.singleValue = this._nubMacroRugo.prms.L.singleValue;
 
-        this.section.prms.LargeurBerge.singleValue = this._nubMacroRugo.prms.B.V;
-        this._nubMacroRugo.prms.Q.singleValue = this.section.prms.Q.singleValue;
-        this.section.prms.If.singleValue = this._nubMacroRugo.prms.If.v;
-        const Z2 = this.prms.Z2.singleValue;
-        const ZF2 = this._nubMacroRugo.result.getValue("ZF2");
-        this.section.prms.YB.singleValue = Math.max((Z2 - ZF2) * 1.5, 1); // pour éviter de fournir Infinity (max avec 1 à cause des fuzz tests)
-        this.section.prms.Ks.singleValue = this._nubMacroRugo.result.resultElement.values.Strickler;
-        this.prms.ZF1.singleValue = this._nubMacroRugo.prms.ZF1.singleValue;
-        this.prms.ZF2.singleValue = ZF2;
-        this.prms.Long.singleValue = this._nubMacroRugo.prms.L.singleValue;
-
-        // set Dx to half of block distance
-        const ax: number = this._nubMacroRugo.prms.PBD.v / Math.sqrt(this._nubMacroRugo.prms.C.v);
-        this.prms.Dx.singleValue = ax / 2;
+            // set Dx to half of block distance
+            const ax: number = this._nubMacroRugo.prms.PBD.v / Math.sqrt(this._nubMacroRugo.prms.C.v);
+            this.prms.Dx.singleValue = ax / 2;
+        }
     }
 
     /**
@@ -94,6 +97,13 @@ export class MacroRugoRemous extends CourbeRemous {
      */
     public CalcSerie(rInit?: number): Result {
         this.syncSectionMacroRugo();
+        if (!this._nubMacroRugo.result.ok) {
+            const res = new Result();
+            res.addLog(this._nubMacroRugo.result.globalLog);
+            res.addLog(this._nubMacroRugo.result.log);
+            return res;
+        }
+
         const res = super.CalcSerie(rInit);
 
         // add warning about downstream fall in case of downstream water elevation < critical elevation
-- 
GitLab