From 5fdbd771ff75adc71edf8f736c4165bbc9022ae2 Mon Sep 17 00:00:00 2001 From: Eric NGUYEN Date: Wed, 31 Aug 2022 10:57:55 +0200 Subject: [PATCH] Add try catch to behaviors --- src/Components/Editor/Behaviors/Behaviors.ts | 39 +++++++++++-------- .../Editor/Behaviors/FlexBehaviors.ts | 3 +- src/utils/simplex.ts | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Components/Editor/Behaviors/Behaviors.ts b/src/Components/Editor/Behaviors/Behaviors.ts index f00bba7..4dac2de 100644 --- a/src/Components/Editor/Behaviors/Behaviors.ts +++ b/src/Components/Editor/Behaviors/Behaviors.ts @@ -13,26 +13,31 @@ import { ApplySymbol } from './SymbolBehaviors'; * @returns Updated container */ export function ApplyBehaviors(container: IContainerModel, symbols: Map): IContainerModel { - if (container.properties.isAnchor) { - ApplyAnchor(container); - } - - Flex(container); - - ApplyRigidBody(container); - - const symbol = symbols.get(container.properties.linkedSymbolId); - if (container.properties.linkedSymbolId !== '' && symbol !== undefined) { - ApplySymbol(container, symbol); - } - - if (APPLY_BEHAVIORS_ON_CHILDREN) { - // Apply DFS by recursion - for (const child of container.children) { - ApplyBehaviors(child, symbols); + try { + if (container.properties.isAnchor) { + ApplyAnchor(container); } + + Flex(container); + + ApplyRigidBody(container); + + const symbol = symbols.get(container.properties.linkedSymbolId); + if (container.properties.linkedSymbolId !== '' && symbol !== undefined) { + ApplySymbol(container, symbol); + } + + if (APPLY_BEHAVIORS_ON_CHILDREN) { + // Apply DFS by recursion + for (const child of container.children) { + ApplyBehaviors(child, symbols); + } + } + } catch (error) { + console.warn(error); } + return container; } diff --git a/src/Components/Editor/Behaviors/FlexBehaviors.ts b/src/Components/Editor/Behaviors/FlexBehaviors.ts index 3b8e34e..498ca5a 100644 --- a/src/Components/Editor/Behaviors/FlexBehaviors.ts +++ b/src/Components/Editor/Behaviors/FlexBehaviors.ts @@ -47,8 +47,7 @@ function FlexGroup(flexibleGroup: IFlexibleGroup): void { // title: 'Cannot fit!', // text: 'Cannot fit at all even when squeezing all flex containers to the minimum.' // }); - console.error('[FlexBehavior] Cannot fit at all even when squeezing all flex containers to the minimum.'); - return; + throw new Error('[FlexBehavior] Cannot fit at all even when squeezing all flex containers to the minimum.'); } const maxMinWidths = Math.max(...minWidths); diff --git a/src/utils/simplex.ts b/src/utils/simplex.ts index ea30731..27f54ba 100644 --- a/src/utils/simplex.ts +++ b/src/utils/simplex.ts @@ -183,7 +183,7 @@ function ApplyMainLoop(oldMatrix: number[][], rowlength: number): number[][] { } if (tries === 0) { - throw new Error('[Flex]Simplexe: Could not find a solution'); + throw new Error('[Flex] Simplexe: Could not find a solution'); } return matrix;