Add try catch to behaviors

This commit is contained in:
Eric NGUYEN 2022-08-31 10:57:55 +02:00
parent 5fdee602f1
commit 5fdbd771ff
3 changed files with 24 additions and 20 deletions

View file

@ -13,26 +13,31 @@ import { ApplySymbol } from './SymbolBehaviors';
* @returns Updated container
*/
export function ApplyBehaviors(container: IContainerModel, symbols: Map<string, ISymbolModel>): 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;
}

View file

@ -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);

View file

@ -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;