From 4757729209b403db014aed953307496f455d34bf Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 22 Feb 2022 01:23:22 -0800 Subject: [PATCH] fix error handling --- web/app/cad/craft/craftPlugin.ts | 14 +++++--- .../cad/craft/wizard/components/Wizard.jsx | 35 +++++++++++++------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/web/app/cad/craft/craftPlugin.ts b/web/app/cad/craft/craftPlugin.ts index ef6231a6..4867ccf7 100644 --- a/web/app/cad/craft/craftPlugin.ts +++ b/web/app/cad/craft/craftPlugin.ts @@ -18,6 +18,7 @@ export function activate(ctx: CoreContext) { const models$ = state([]); const update$ = stream(); + const pipelineFailure$ = state(null); models$.attach(models => models.forEach(model => model.traverse(m => { if (m instanceof MFace) { @@ -110,7 +111,7 @@ export function activate(ctx: CoreContext) { ctx.craftService = { modify, modifyInHistoryAndStep, reset, rebuild, runRequest, runPipeline, historyTravel: historyTravel(modifications$), - modifications$, models$, update$, isEditingHistory + modifications$, models$, update$, isEditingHistory, pipelineFailure$ }; // @ts-ignore @@ -124,6 +125,8 @@ export function activate(ctx: CoreContext) { function runPipeline(history: OperationRequest[], beginIndex: number, endIndex: number): Promise { + pipelineFailure$.next(null); + const models: Set = new Set(models$.value); return new Promise((resolve, reject) => { @@ -143,14 +146,14 @@ export function activate(ctx: CoreContext) { runPromise(i + 1); }).catch(error => { - debugger + pipelineFailure$.next(error) reject({ - failIndex: i, + failIndex: i - 1 , error }); }) } - runPromise(beginIndex); + return runPromise(beginIndex); }); } @@ -182,7 +185,7 @@ export function activate(ctx: CoreContext) { //TODO: need to find a way to propagate the error to the wizard. next({ ...curr, - pointer: reason.failIndex + pointer: reason.failIndex, }); }); }) @@ -251,6 +254,7 @@ interface CraftService { modifications$: StateStream; models$: StateStream; update$: Emitter; + pipelineFailure$: StateStream modify(request: OperationRequest, onAccepted: () => void, onError: () => Error); diff --git a/web/app/cad/craft/wizard/components/Wizard.jsx b/web/app/cad/craft/wizard/components/Wizard.jsx index 47d75c40..b4abd940 100644 --- a/web/app/cad/craft/wizard/components/Wizard.jsx +++ b/web/app/cad/craft/wizard/components/Wizard.jsx @@ -9,6 +9,8 @@ import {FormContext, FormContextData} from './form/Form'; import connect from 'ui/connect'; import {combine} from 'lstream'; import {GenericWizard} from "ui/components/GenericWizard"; +import * as PropTypes from "prop-types"; +import {useStream} from "ui/effects"; @connect((streams, props) => combine(props.context.workingRequest$, props.context.state$) .map(([workingRequest, state]) => ({ @@ -54,19 +56,15 @@ export default class Wizard extends React.Component { topicId={operation.id} onCancel={this.cancel} onOK={this.onOK} - infoText={error &&
- {CadError.ALGORITHM_ERROR_KINDS.includes(error.kind) && - performing operation with current parameters leads to an invalid object - (self-intersecting / zero-thickness / complete degeneration or unsupported cases) - } - {error.code &&
{error.code}
} - {error.userMessage &&
{error.userMessage}
} - {!error.userMessage &&
internal error processing operation, check the log
} -
} + infoText={<> + {error && } + + } >
+ ; } @@ -100,5 +98,22 @@ export default class Wizard extends React.Component { this.props.onOK(); }; } +function PipelineError() { + const pipelineFailure = useStream(ctx => ctx.craftService.pipelineFailure$); + if (!pipelineFailure) { + return null; + } + return +} - +function ErrorPrinter({error}) { + return
+ {CadError.ALGORITHM_ERROR_KINDS.includes(error.kind) && + performing operation with current parameters leads to an invalid object + (self-intersecting / zero-thickness / complete degeneration or unsupported cases) + } + {error.code &&
{error.code}
} + {error.userMessage &&
{error.userMessage}
} + {!error.userMessage &&
internal error processing operation, check the log
} +
+}