fix error handling

This commit is contained in:
Val Erastov 2022-02-22 01:23:22 -08:00
parent 3d2faf9256
commit 4757729209
2 changed files with 34 additions and 15 deletions

View file

@ -18,6 +18,7 @@ export function activate(ctx: CoreContext) {
const models$ = state<MObject[]>([]);
const update$ = stream<void>();
const pipelineFailure$ = state<any>(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<void> {
pipelineFailure$.next(null);
const models: Set<MObject> = 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<CraftHistory>;
models$: StateStream<MObject[]>;
update$: Emitter<void>;
pipelineFailure$: StateStream<any>
modify(request: OperationRequest, onAccepted: () => void, onError: () => Error);

View file

@ -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 && <div className={ls.errorMessage}>
{CadError.ALGORITHM_ERROR_KINDS.includes(error.kind) && <span>
performing operation with current parameters leads to an invalid object
(self-intersecting / zero-thickness / complete degeneration or unsupported cases)
</span>}
{error.code && <div className={ls.errorCode}>{error.code}</div>}
{error.userMessage && <div className={ls.userErrorMessage}>{error.userMessage}</div>}
{!error.userMessage && <div>internal error processing operation, check the log</div>}
</div>}
infoText={<>
{error && <ErrorPrinter error={error}/>}
<PipelineError />
</>}
>
<FormContext.Provider value={new FormContextData(this.props.context, [])}>
<Form/>
</FormContext.Provider>
</GenericWizard>;
}
@ -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 <ErrorPrinter error={pipelineFailure}/>
}
function ErrorPrinter({error}) {
return <div className={ls.errorMessage}>
{CadError.ALGORITHM_ERROR_KINDS.includes(error.kind) && <span>
performing operation with current parameters leads to an invalid object
(self-intersecting / zero-thickness / complete degeneration or unsupported cases)
</span>}
{error.code && <div className={ls.errorCode}>{error.code}</div>}
{error.userMessage && <div className={ls.userErrorMessage}>{error.userMessage}</div>}
{!error.userMessage && <div>internal error processing operation, check the log</div>}
</div>
}