From 18b88463bcc526261ae4e9b7b0e403d43b97ce48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 6 Dec 2022 14:13:57 +0100 Subject: [PATCH] refactor: improve Message information about parents refs #330 --- src/dichotomie.ts | 2 +- src/prebarrage/pre_barrage.ts | 2 +- src/util/log.ts | 2 +- src/util/message.ts | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dichotomie.ts b/src/dichotomie.ts index d90fcf86..a4bb12e8 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -116,7 +116,7 @@ export class Dichotomie extends Debug { ); return new Result(new Message(MessageCode.ERROR_DICHO_CONVERGE, { lastApproximation: s.value - })); + }), this.nub); } } else { return new Result(r.res); diff --git a/src/prebarrage/pre_barrage.ts b/src/prebarrage/pre_barrage.ts index 79719f20..414fc7be 100644 --- a/src/prebarrage/pre_barrage.ts +++ b/src/prebarrage/pre_barrage.ts @@ -430,7 +430,7 @@ export class PreBarrage extends Nub { } // console.debug(tQ); // console.debug(tZ1); - const r = new Result(this.prms.Z1.v); + const r = new Result(this.prms.Z1.v, this); if(!bConverged) { r.resultElement.addMessage(new Message(MessageCode.WARNING_PREBARRAGE_NON_CONVERGENCE, { precision: (z1stat.max - z1stat.min) diff --git a/src/util/log.ts b/src/util/log.ts index 2f5b9f4f..bc023847 100644 --- a/src/util/log.ts +++ b/src/util/log.ts @@ -26,7 +26,7 @@ export class cLog { public add(m: Message) { // add pointer to the current log as message's parent, unless the message // already has a parent, and unless the current log has no pointer to a result - if (m.parent === undefined && this.parent !== undefined) { + if (m.parent === undefined) { m.parent = this; } this._messages.push(m); diff --git a/src/util/message.ts b/src/util/message.ts index 2d032ccb..2010f77c 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -1,4 +1,5 @@ import { cLog } from "./log"; +import { Nub } from "../nub"; export enum MessageCode { @@ -739,7 +740,12 @@ export class Message { throw new Error("Message.getSeverity() : valeur de code '" + this._code + "' invalide"); } + public get sourceNub(): Nub { + return this.parent?.parent?.sourceNub; + } + public toString(): string { - return MessageCode[this._code] + " " + JSON.stringify(this.extraVar); + const sourceNub = this.sourceNub; + return MessageCode[this._code] + " " + JSON.stringify(this.extraVar) + (sourceNub === undefined ? "" : " parentnub " + sourceNub.constructor.name); } } -- GitLab