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

Improve error handling and logging in background execution and extension activation #15435

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/standalone/api/kernels/backgroundExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ del __jupyter_exec_background__
disposables.add(token.onCancellationRequested(() => disposables.dispose()));
const promise = raceCancellation(
token,
new Promise<T | undefined>((resolve) => {
new Promise<T | undefined>((resolve, reject) => {
disposables.add(
api.onDidReceiveDisplayUpdate(async (output) => {
if (token.isCancellationRequested) {
Expand All @@ -69,7 +69,12 @@ del __jupyter_exec_background__
if (!result) {
return;
}
return resolve(JSON.parse(new TextDecoder().decode(result.data)) as T);

try {
return resolve(JSON.parse(new TextDecoder().decode(result.data)) as T);
} catch (ex) {
return reject(new Error('Failed to parse the result', ex));
}
})
);
})
Expand Down
20 changes: 13 additions & 7 deletions src/standalone/chat/extesnion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { execCodeInBackgroundThread } from '../api/kernels/backgroundExecution';
import { ServiceContainer } from '../../platform/ioc/container';
import { IControllerRegistration } from '../../notebooks/controllers/types';
import { JupyterVariablesProvider } from '../../kernels/variables/JupyterVariablesProvider';
import { traceWarning } from '../../platform/logging';

export async function activate(context: vscode.ExtensionContext): Promise<void> {
context.subscriptions.push(
Expand All @@ -23,8 +24,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
if (Array.isArray(result.content)) {
return result.content;
}
} catch (_) {
} catch (ex) {
// ignore
traceWarning('Failed to get pip packages', ex);
}
}
}
Expand Down Expand Up @@ -85,12 +87,16 @@ stdout, stderr = proc.communicate()
return stdout
`.split('\n');

const content = await execCodeInBackgroundThread<KernelMessage.IInspectReplyMsg['content']>(
kernel,
codeToExecute,
token
);
return { content } as KernelMessage.IInspectReplyMsg;
try {
const content = await execCodeInBackgroundThread<KernelMessage.IInspectReplyMsg['content']>(
kernel,
codeToExecute,
token
);
return { content } as KernelMessage.IInspectReplyMsg;
} catch (ex) {
throw ex;
}
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Loading