Skip to content

Commit

Permalink
Fix canceling regression (#2967)
Browse files Browse the repository at this point in the history
* Fix canceling regression

* reorder

* return same as old code

* Use new error type

* better check

* Remove domexception and assertNever on error

* Update src/renderer/contexts/ExecutionContext.tsx

Co-authored-by: Michael Schmidt <[email protected]>

* remove unused stuff

---------

Co-authored-by: Michael Schmidt <[email protected]>
  • Loading branch information
joeyballentine and RunDevelopment authored Jun 30, 2024
1 parent 49d68b2 commit 5a44f28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/common/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosRequestConfig } from 'axios';
import axios, { AxiosRequestConfig, Cancel } from 'axios';
import {
BackendJsonNode,
Category,
Expand All @@ -17,6 +17,7 @@ import {
SchemaId,
Version,
} from './common-types';
import { assertNever } from './util';

export interface BackendSuccessResponse {
type: 'success';
Expand Down Expand Up @@ -133,6 +134,21 @@ export class ServerError extends Error {
return new ServerError(json.message, json.description, json.status);
}
}
export class CancelError extends Error {
message: string;

config: AxiosRequestConfig | undefined;

constructor(message: string | undefined, config?: AxiosRequestConfig) {
super();
this.message = message ?? 'The request was cancelled';
this.config = config;
}

static fromCancel(cancelData: Cancel, config?: AxiosRequestConfig): CancelError {
return new CancelError(cancelData.message, config);
}
}

/**
* A wrapper to communicate with the backend.
Expand Down Expand Up @@ -182,6 +198,10 @@ export class Backend {
if (error.response?.data) {
return error.response.data as T;
}
if (axios.isCancel(error)) {
throw CancelError.fromCancel(error, error.config);
}
assertNever(error);
}
if (ServerError.isJson(error)) {
throw ServerError.fromJson(error);
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/contexts/ExecutionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BackendEventMap,
BackendStatusResponse,
BackendWorkerStatusResponse,
CancelError,
} from '../../common/Backend';
import { EdgeData, NodeData, OutputId } from '../../common/common-types';
import { formatExecutionErrorMessage } from '../../common/formatExecutionErrorMessage';
Expand Down Expand Up @@ -478,7 +479,7 @@ export const ExecutionProvider = memo(({ children }: React.PropsWithChildren<{}>
});
}
} catch (err: unknown) {
if (!(err instanceof DOMException && err.name === 'AbortError')) {
if (!(err instanceof CancelError)) {
sendAlert({
type: AlertType.ERROR,
message: `An unexpected error occurred: ${String(err)}`,
Expand Down

0 comments on commit 5a44f28

Please sign in to comment.