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

Error message for failures in remote kernel picker #14124

Merged
merged 1 commit into from
Aug 15, 2023
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
2 changes: 1 addition & 1 deletion src/kernels/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IContributedKernelFinder<T extends KernelConnectionMetadata = K
* Last error thrown when listing the kernels.
* Use this property to determine if there was an error fetching kernels when there are no kernels listed.
*/
lastError?: Error;
readonly lastError?: Error;
id: string;
displayName: string;
kind: ContributedKernelFinderKind;
Expand Down
1 change: 1 addition & 0 deletions src/kernels/jupyter/finder/remoteKernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
if (!(ex instanceof CancellationError)) {
traceError('UniversalRemoteKernelFinder: Failed to get kernels without cache', ex);
this._lastError = ex;
this._onDidChange.fire();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,17 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel
label: this.displayDataProvider.getDisplayData(item).category || 'Other'
};
};
const remoteKernelPicker = new BaseProviderBasedQuickPick(source, quickPickFactory, getCategory, {
supportsBack: true
const errorToQuickPickItem = (_error: Error) => ({
label: DataScience.failedToFetchKernelSpecsRemoteErrorMessageForQuickPickLabel,
detail: DataScience.failedToFetchKernelSpecsRemoteErrorMessageForQuickPickDetail
});
const remoteKernelPicker = new BaseProviderBasedQuickPick(
source,
quickPickFactory,
getCategory,
{ supportsBack: true },
errorToQuickPickItem
);
const preferred = new PreferredKernelConnectionService(this.jupyterConnection);
source
.then((source) => preferred.findPreferredRemoteKernelConnection(notebook, source, token))
Expand Down
33 changes: 31 additions & 2 deletions src/platform/common/providerBasedQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export interface IQuickPickItemProvider<T extends { id: string }> {
readonly title: string;
onDidChange: Event<void>;
onDidChangeStatus: Event<void>;
/**
* Last error thrown when listing the items.
*/
readonly lastError?: Error;
readonly items: readonly T[];
readonly status: 'discovering' | 'idle';
refresh(): Promise<void>;
Expand All @@ -67,6 +71,7 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
private quickPick?: QuickPick<QuickPickItem>;
private previouslyEnteredValue: string = '';
private previouslySelectedItem?: CommandQuickPickItem<T>;
private resolvedProvider?: IQuickPickItemProvider<T>;
constructor(
private readonly provider: Promise<IQuickPickItemProvider<T>>,
private readonly createQuickPickItem: (item: T, provider: BaseProviderBasedQuickPick<T>) => QuickPickItem,
Expand All @@ -76,7 +81,11 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
) => { label: string; sortKey?: string },
private readonly options: {
supportsBack: boolean;
}
},
private readonly createErrorQuickPickItem?: (
error: Error,
provider: BaseProviderBasedQuickPick<T>
) => QuickPickItem
) {
super();
}
Expand Down Expand Up @@ -114,6 +123,7 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
return this._selected;
}
private readonly quickPickItemMap = new WeakSet<SelectorQuickPickItem<T>>();
private readonly errorQuickPickItemMap = new WeakSet<QuickPickItem>();
private createQuickPick() {
const disposables: IDisposable[] = [];
const refreshButton: QuickInputButton = { iconPath: new ThemeIcon('refresh'), tooltip: Common.refresh };
Expand All @@ -130,6 +140,7 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
quickPick.title = DataScience.kernelPickerSelectKernelFromRemoteTitleWithoutName;
this.provider
.then((provider) => {
this.resolvedProvider = provider;
quickPick.title = DataScience.kernelPickerSelectKernelFromRemoteTitle(provider.title);
quickPick.busy = provider.status === 'discovering';
provider.onDidChange(() => this.updateQuickPickItems(quickPick, provider), this, disposables);
Expand Down Expand Up @@ -213,6 +224,8 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
resolve(selection.item);
} else if (this.isCommandQuickPickItem(selection)) {
resolve(selection);
} else if (this.isErrorQuickPickItem(selection)) {
resolve(InputFlowAction.cancel);
}
}
});
Expand Down Expand Up @@ -374,10 +387,15 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
selectedQuickPickItem = undefined;
}
}
const errorItem = this.resolvedProvider?.lastError
? this.toErrorQuickPickItem(this.resolvedProvider.lastError)
: undefined;

const items = (<QuickPickItem[]>[])
.concat(Array.from(this.commands.values()))
.concat(recommendedItems)
.concat(connections);
.concat(connections)
.concat(errorItem ? [errorItem] : []);
const activeItems = selectedQuickPickItem
? [selectedQuickPickItem]
: quickPick.activeItems.length
Expand Down Expand Up @@ -406,6 +424,17 @@ export class BaseProviderBasedQuickPick<T extends { id: string }> extends Dispos
quickPick.activeItems = [this.previouslySelectedItem];
}
}
private isErrorQuickPickItem(item: QuickPickItem): item is QuickPickItem {
return this.errorQuickPickItemMap.has(item as unknown as QuickPickItem);
}
private toErrorQuickPickItem(error: Error): QuickPickItem | undefined {
if (!this.createErrorQuickPickItem) {
return;
}
const quickPickItem = this.createErrorQuickPickItem(error, this);
this.errorQuickPickItemMap.add(quickPickItem);
return quickPickItem;
}
private isSelectorQuickPickItem(item: QuickPickItem): item is SelectorQuickPickItem<T> {
return this.quickPickItemMap.has(item as unknown as SelectorQuickPickItem<T>);
}
Expand Down
Loading