Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix canceling regression #2967

Merged
merged 8 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 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 Down Expand Up @@ -133,6 +133,27 @@ export class ServerError extends Error {
return new ServerError(json.message, json.description, json.status);
}
}
export class CancelError extends Error {
type = 'cancel';

joeyballentine marked this conversation as resolved.
Show resolved Hide resolved
message: string;

config: AxiosRequestConfig | undefined;

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

static isCancel(cancel: unknown): cancel is CancelError {
return cancel instanceof CancelError;
}

joeyballentine marked this conversation as resolved.
Show resolved Hide resolved
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 +203,9 @@ export class Backend {
if (error.response?.data) {
return error.response.data as T;
}
if (axios.isCancel(error)) {
throw CancelError.fromCancel(error, error.config);
}
}
if (ServerError.isJson(error)) {
throw ServerError.fromJson(error);
Expand Down
6 changes: 5 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,10 @@ export const ExecutionProvider = memo(({ children }: React.PropsWithChildren<{}>
});
}
} catch (err: unknown) {
if (!(err instanceof DOMException && err.name === 'AbortError')) {
if (
!(err instanceof DOMException && err.name === 'AbortError') &&
joeyballentine marked this conversation as resolved.
Show resolved Hide resolved
!CancelError.isCancel(err)
) {
sendAlert({
type: AlertType.ERROR,
message: `An unexpected error occurred: ${String(err)}`,
Expand Down
Loading