Commit 3f44ff89 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Fix nghyd#263 - hide session loading errors that have no consequences

Showing with 20 additions and 7 deletions
+20 -7
...@@ -246,6 +246,14 @@ describe("serialising / deserialising session - ", () => { ...@@ -246,6 +246,14 @@ describe("serialising / deserialising session - ", () => {
}); });
it ("nghyd#263 - errors without consequences should not appear", () => {
Session.getInstance().clear();
// tslint:disable-next-line:max-line-length
const json = `{"header":{"source":"jalhyd","format_version":"1.1","created":"2019-07-31T12:08:20.284Z"},"session":[{"uid":"NjdmM3","props":{"calcType":"PabChute","nodeType":"None"},"meta":{"title":"PAB : chute"},"children":[],"parameters":[{"symbol":"Z1","mode":"SINGLE","value":29.99},{"symbol":"Z2","mode":"SINGLE","value":26.81},{"symbol":"DH","mode":"CALCUL"}]},{"uid":"eWNjdG","props":{"calcType":"PabNombre","nodeType":"None"},"meta":{"title":"PAB : nombre"},"children":[],"parameters":[{"symbol":"DHT","mode":"LINK","targetNub":"NjdmM3","targetParam":"DH"},{"symbol":"N","mode":"SINGLE","value":14},{"symbol":"DH","mode":"CALCUL"}]},{"uid":"dXM4em","props":{"calcType":"PabPuissance","nodeType":"None"},"meta":{"title":"PAB : puissance"},"children":[],"parameters":[{"symbol":"DH","mode":"LINK","targetNub":"eWNjdG","targetParam":"DH"},{"symbol":"Q","mode":"SINGLE","value":1.8},{"symbol":"V","mode":"CALCUL"},{"symbol":"PV","mode":"SINGLE","value":140}]},{"uid":"bzNlaX","props":{"calcType":"PabDimensions","nodeType":"None"},"meta":{"title":"PAB : dimensions"},"children":[],"parameters":[{"symbol":"L","mode":"SINGLE","value":5},{"symbol":"W","mode":"SINGLE","value":3.6},{"symbol":"Y","mode":"CALCUL"},{"symbol":"V","mode":"LINK","targetNub":"dXM4em","targetParam":"V"}]},{"uid":"cGI5d3","props":{"calcType":"Cloisons","nodeType":"None"},"meta":{"title":"Cloisons"},"children":[{"uid":"ZzZzbD","props":{"calcType":"Structure","structureType":"SeuilRectangulaire","loiDebit":"WeirSubmergedLarinier"},"children":[],"parameters":[{"symbol":"h1","mode":"CALCUL"},{"symbol":"L","mode":"SINGLE","value":0.5},{"symbol":"CdWSL","mode":"SINGLE","value":0.83}]}],"parameters":[{"symbol":"Q","mode":"LINK","targetNub":"dXM4em","targetParam":"Q"},{"symbol":"Z1","mode":"SINGLE","value":30.14},{"symbol":"LB","mode":"SINGLE","value":4.5},{"symbol":"BB","mode":"LINK","targetNub":"bzNlaX","targetParam":"W"},{"symbol":"PB","mode":"SINGLE","value":2.5},{"symbol":"DH","mode":"LINK","targetNub":"eWNjdG","targetParam":"DH"}]}]}`;
const res = Session.getInstance().unserialise(json);
expect(res.hasErrors).toBe(false);
});
}); });
describe("nodeType property - ", () => { describe("nodeType property - ", () => {
......
...@@ -102,7 +102,7 @@ export class ParamDefinition implements INamedIterableValues, IObservable { ...@@ -102,7 +102,7 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
private _observable: Observable; private _observable: Observable;
constructor(parent: ParamsEquation, symb: string, d: ParamDomain | ParamDomainValue, unit?: string, constructor(parent: ParamsEquation, symb: string, d: ParamDomain | ParamDomainValue, unit?: string,
val?: number, family?: ParamFamily, visible: boolean = true val?: number, family?: ParamFamily, visible: boolean = true
) { ) {
this._parent = parent; this._parent = parent;
this._symbol = symb; this._symbol = symb;
...@@ -826,9 +826,12 @@ export class ParamDefinition implements INamedIterableValues, IObservable { ...@@ -826,9 +826,12 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
try { try {
this.valueMode = mode; this.valueMode = mode;
} catch (err) { } catch (err) {
ret.hasErrors = true; // silent fail : impossible to determine if this is an error, because
// tslint:disable-next-line:no-console // at this time, it is possible that no candidate for calculatedParam can
console.error("loadObjectRepresentation: set valueMode error"); // be found, since Nub children are not loaded yet (see nghyd#263)
/* ret.hasErrors = true;
console.error("loadObjectRepresentation: set valueMode error"); */
} }
} }
...@@ -867,10 +870,12 @@ export class ParamDefinition implements INamedIterableValues, IObservable { ...@@ -867,10 +870,12 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
try { try {
this.defineReference(destNub, obj.targetParam); this.defineReference(destNub, obj.targetParam);
} catch (err) { } catch (err) {
ret.hasErrors = true; // silent fail : impossible to determine if this is an error, because
// tslint:disable-next-line:no-console // fixLinks() might solve it later
/* ret.hasErrors = true;
console.error("loadObjectRepresentation: defineReference error" console.error("loadObjectRepresentation: defineReference error"
+ ` (${this.symbol} => ${destNub.uid}.${obj.targetParam})`); + ` (${this.symbol} => ${destNub.uid}.${obj.targetParam})`); */
} }
} // si la cible du lien n'existe pas, Session.fixLinks() est censé s'en occuper } // si la cible du lien n'existe pas, Session.fixLinks() est censé s'en occuper
break; break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment