Skip to content

Commit 5ea5395

Browse files
committed
Adds logging & better error handling
1 parent c8e7231 commit 5ea5395

File tree

4 files changed

+269
-170
lines changed

4 files changed

+269
-170
lines changed

src/plus/focus/focus.ts

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { QuickInputButton } from 'vscode';
1+
import type { QuickInputButton, QuickPick } from 'vscode';
22
import { commands, Uri } from 'vscode';
33
import { getAvatarUri } from '../../avatars';
44
import type {
@@ -88,6 +88,8 @@ export interface FocusItemQuickPickItem extends QuickPickItemOfT<FocusItem> {
8888

8989
interface Context {
9090
items: FocusItem[];
91+
itemsError?: Error;
92+
9193
title: string;
9294
collapsed: Map<FocusGroup, boolean>;
9395
telemetryContext: LaunchpadTelemetryContext | undefined;
@@ -192,6 +194,7 @@ export class FocusCommand extends QuickCommand<State> {
192194

193195
const context: Context = {
194196
items: [],
197+
itemsError: undefined,
195198
title: this.title,
196199
collapsed: collapsed,
197200
telemetryContext: this.telemetryContext,
@@ -412,13 +415,48 @@ export class FocusCommand extends QuickCommand<State> {
412415
return items;
413416
};
414417

415-
const items = getItems(context.items);
418+
function getItemsAndPlaceholder() {
419+
if (context.itemsError != null) {
420+
return {
421+
placeholder: `Unable to load items (${String(context.itemsError)})`,
422+
items: [createDirectiveQuickPickItem(Directive.Cancel, undefined, { label: 'OK' })],
423+
};
424+
}
425+
426+
if (!context.items.length) {
427+
return {
428+
placeholder: 'All done! Take a vacation',
429+
items: [createDirectiveQuickPickItem(Directive.Cancel, undefined, { label: 'OK' })],
430+
};
431+
}
432+
433+
return {
434+
placeholder: 'Choose an item to focus on',
435+
items: getItems(context.items),
436+
};
437+
}
438+
439+
const updateItems = async (quickpick: QuickPick<FocusItemQuickPickItem | DirectiveQuickPickItem>) => {
440+
quickpick.busy = true;
441+
442+
try {
443+
await updateContextItems(this.container, context, { force: true });
444+
445+
const { items, placeholder } = getItemsAndPlaceholder();
446+
quickpick.placeholder = placeholder;
447+
quickpick.items = items;
448+
} finally {
449+
quickpick.busy = false;
450+
}
451+
};
452+
453+
const { items, placeholder } = getItemsAndPlaceholder();
416454

417455
const step = createPickStep({
418456
title: context.title,
419-
placeholder: !items.length ? 'All done! Take a vacation' : 'Choose an item to focus on',
457+
placeholder: placeholder,
420458
matchOnDetail: true,
421-
items: !items.length ? [createDirectiveQuickPickItem(Directive.Cancel, undefined, { label: 'OK' })] : items,
459+
items: items,
422460
buttons: [
423461
FeedbackQuickInputButton,
424462
OpenInEditorQuickInputButton,
@@ -438,19 +476,7 @@ export class FocusCommand extends QuickCommand<State> {
438476
void executeCommand(Commands.ShowFocusPage);
439477
break;
440478
case RefreshQuickInputButton:
441-
quickpick.busy = true;
442-
443-
try {
444-
await updateContextItems(this.container, context, { force: true });
445-
const items = getItems(context.items);
446-
447-
quickpick.placeholder = !items.length
448-
? 'All done! Take a vacation'
449-
: 'Choose an item to focus on';
450-
quickpick.items = items;
451-
} finally {
452-
quickpick.busy = false;
453-
}
479+
await updateItems(quickpick);
454480
break;
455481
}
456482
},
@@ -482,17 +508,7 @@ export class FocusCommand extends QuickCommand<State> {
482508
}
483509

484510
this.sendItemActionTelemetry(button, item, group, context);
485-
quickpick.busy = true;
486-
487-
try {
488-
await updateContextItems(this.container, context);
489-
const items = getItems(context.items);
490-
491-
quickpick.placeholder = !items.length ? 'All done! Take a vacation' : 'Choose an item to focus on';
492-
quickpick.items = items;
493-
} finally {
494-
quickpick.busy = false;
495-
}
511+
await updateItems(quickpick);
496512
},
497513
});
498514

@@ -972,7 +988,13 @@ export class FocusCommand extends QuickCommand<State> {
972988
}
973989

974990
async function updateContextItems(container: Container, context: Context, options?: { force?: boolean }) {
975-
context.items = await container.focus.getCategorizedItems(options);
991+
try {
992+
context.items = await container.focus.getCategorizedItems(options);
993+
context.itemsError = undefined;
994+
} catch (ex) {
995+
context.items = [];
996+
context.itemsError = ex;
997+
}
976998
if (container.telemetry.enabled) {
977999
updateTelemetryContext(context);
9781000
}

src/plus/focus/focusIndicator.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { FocusCommandArgs } from './focus';
1414
import type { FocusGroup, FocusItem, FocusProvider, FocusRefreshEvent } from './focusProvider';
1515
import { groupAndSortFocusItems, supportedFocusIntegrations } from './focusProvider';
1616

17-
type FocusIndicatorState = 'idle' | 'disconnected' | 'loading' | 'load';
17+
type FocusIndicatorState = 'idle' | 'disconnected' | 'loading' | 'load' | 'failed';
1818

1919
export class FocusIndicator implements Disposable {
2020
private readonly _disposable: Disposable;
@@ -112,6 +112,12 @@ export class FocusIndicator implements Disposable {
112112
private onFocusRefreshed(e: FocusRefreshEvent) {
113113
if (this._statusBarFocus == null || !configuration.get('launchpad.indicator.polling.enabled')) return;
114114

115+
if (e.error != null) {
116+
this.updateStatusBar('failed');
117+
118+
return;
119+
}
120+
115121
this.updateStatusBar('load', e.items);
116122
}
117123

@@ -249,14 +255,21 @@ export class FocusIndicator implements Disposable {
249255
this.startRefreshTimer(5000);
250256
tooltip.appendMarkdown('\n\n---\n\n$(loading~spin) Loading...');
251257

252-
this._statusBarFocus.text = '$(loading~spin)';
258+
this._statusBarFocus.text = '$(rocket)$(loading~spin)';
253259
this._statusBarFocus.tooltip = tooltip;
254260
this._statusBarFocus.color = undefined;
255261
break;
256262

257263
case 'load':
258264
this.updateStatusBarWithItems(tooltip, categorizedItems);
259265
break;
266+
267+
case 'failed':
268+
this.clearRefreshTimer();
269+
tooltip.appendMarkdown('\n\n---\n\n$(alert) Unable to load items');
270+
271+
this._statusBarFocus.text = '$(rocket)$(alert)';
272+
this._statusBarFocus.tooltip = tooltip;
260273
}
261274
}
262275

0 commit comments

Comments
 (0)