Skip to content

Commit

Permalink
Avoids dangling promises
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 10, 2024
1 parent 79783b0 commit 4d2e632
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,12 @@ async function confirmAIProviderToS<Provider extends AIProviders>(
if (result === accept) return true;

if (result === acceptWorkspace) {
void storage.storeWorkspace(`confirm:ai:tos:${model.provider.id}`, true);
void storage.storeWorkspace(`confirm:ai:tos:${model.provider.id}`, true).catch();
return true;
}

if (result === acceptAlways) {
void storage.store(`confirm:ai:tos:${model.provider.id}`, true);
void storage.store(`confirm:ai:tos:${model.provider.id}`, true).catch();
return true;
}

Expand Down Expand Up @@ -642,7 +642,7 @@ export async function getOrPromptApiKey(

if (!apiKey) return undefined;

void storage.storeSecret(`gitlens.${provider.id}.key`, apiKey);
void storage.storeSecret(`gitlens.${provider.id}.key`, apiKey).catch();
}

return apiKey;
Expand Down
2 changes: 1 addition & 1 deletion src/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _onDidFetchAvatar.event(
),
]
: undefined;
void Container.instance.storage.store('avatars', avatars);
void Container.instance.storage.store('avatars', avatars).catch();
}, 1000),
);

Expand Down
2 changes: 1 addition & 1 deletion src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export class LocalGitProvider implements GitProvider, Disposable {

const location = await any<GitLocation>(findGitPromise, findGitFromSCMPromise);
// Save the found git path, but let things settle first to not impact startup performance
setTimeout(() => void this.container.storage.storeWorkspace('gitPath', location.path), 1000);
setTimeout(() => void this.container.storage.storeWorkspace('gitPath', location.path).catch(), 1000);

if (scope != null) {
setLogScopeExit(
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |

void showWhatsNew(container, gitlensVersion, prerelease, previousVersion);

void storage.store(prerelease ? 'preVersion' : 'version', gitlensVersion);
void storage.store(prerelease ? 'preVersion' : 'version', gitlensVersion).catch();

// Only update our synced version if the new version is greater
if (syncedVersion == null || compare(gitlensVersion, syncedVersion) === 1) {
void storage.store(prerelease ? 'synced:preVersion' : 'synced:version', gitlensVersion);
void storage.store(prerelease ? 'synced:preVersion' : 'synced:version', gitlensVersion).catch();
}

if (logLevel === 'debug') {
Expand Down
2 changes: 1 addition & 1 deletion src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ export class GitProviderService implements Disposable {
private updateVisibilityCache(key: string, visibilityInfo: RepositoryVisibilityInfo): void {
this.ensureRepoVisibilityCache();
this._repoVisibilityCache?.set(key, visibilityInfo);
void this.container.storage.store('repoVisibility', Array.from(this._repoVisibilityCache!.entries()));
void this.container.storage.store('repoVisibility', Array.from(this._repoVisibilityCache!.entries())).catch();
}

@debug()
Expand Down
16 changes: 9 additions & 7 deletions src/plus/gk/account/subscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,13 @@ export class SubscriptionService implements Disposable {
private storeCheckInData(data: GKCheckInResponse): void {
if (data.user?.id == null) return;

void this.container.storage.store(`gk:${data.user.id}:checkin`, {
v: 1,
timestamp: Date.now(),
data: data,
});
void this.container.storage
.store(`gk:${data.user.id}:checkin`, {
v: 1,
timestamp: Date.now(),
data: data,
})
.catch();
}

private async loadStoredCheckInData(userId: string): Promise<GKCheckInResponse | undefined> {
Expand Down Expand Up @@ -1373,7 +1375,7 @@ export class SubscriptionService implements Disposable {
// If the previous and new subscriptions are exactly the same, kick out
if (matches) {
if (options?.store) {
void this.storeSubscription(subscription);
void this.storeSubscription(subscription).catch();
}
return;
}
Expand All @@ -1391,7 +1393,7 @@ export class SubscriptionService implements Disposable {
});

if (options?.store !== false) {
void this.storeSubscription(subscription);
void this.storeSubscription(subscription).catch();
}

this._subscription = subscription;
Expand Down
2 changes: 1 addition & 1 deletion src/plus/integrations/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export abstract class IntegrationBase<
// Don't store the disconnected flag if silently disconnecting or disconnecting this only for
// this current VS Code session (will be re-connected on next restart)
if (!options?.currentSessionOnly && !options?.silent) {
void this.container.storage.storeWorkspace(this.connectedKey, false);
void this.container.storage.storeWorkspace(this.connectedKey, false).catch();
}

this._onDidChange.fire();
Expand Down
2 changes: 1 addition & 1 deletion src/plus/launchpad/launchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
args?.source === 'launchpad-indicator' &&
container.storage.get('launchpad:indicator:hasInteracted') == null
) {
void container.storage.store('launchpad:indicator:hasInteracted', new Date().toISOString());
void container.storage.store('launchpad:indicator:hasInteracted', new Date().toISOString()).catch();
}

this.source = { source: args?.source ?? 'commandPalette' };
Expand Down
2 changes: 1 addition & 1 deletion src/plus/launchpad/launchpadIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ export class LaunchpadIndicator implements Disposable {

const hasLoaded = this.container.storage.get('launchpad:indicator:hasLoaded') ?? false;
if (!hasLoaded) {
void this.container.storage.store('launchpad:indicator:hasLoaded', true);
void this.container.storage.store('launchpad:indicator:hasLoaded', true).catch();
this.container.telemetry.sendEvent('launchpad/indicator/firstLoad');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plus/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function confirmDraftStorage(container: Container): Promise<boolean
);

if (result === accept) {
void container.storage.store('confirm:draft:storage', true);
void container.storage.store('confirm:draft:storage', true).catch();
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plus/webviews/graph/graphWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
}

updateGraphSearchMode(params: UpdateGraphSearchModeParams) {
void this.container.storage.store('graph:searchMode', params.searchMode);
void this.container.storage.store('graph:searchMode', params.searchMode).catch();
}

private _showActiveSelectionDetailsDebounced:
Expand Down Expand Up @@ -2591,7 +2591,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
for (const [key, value] of Object.entries(columnsCfg)) {
columns = updateRecordValue(columns, key, value);
}
void this.container.storage.storeWorkspace('graph:columns', columns);
void this.container.storage.storeWorkspace('graph:columns', columns).catch();
void this.notifyDidChangeColumns();
}

Expand Down
2 changes: 1 addition & 1 deletion src/system/vscode/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function registerCommand(command: string, callback: CommandCallback, this
'context.submode': context?.submode,
});
}
void Container.instance.usage.track(`command:${command as Commands}:executed`);
void Container.instance.usage.track(`command:${command as Commands}:executed`).catch();
callback.call(this, ...args);
},
thisArg,
Expand Down
4 changes: 2 additions & 2 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CompareBranchNode extends SubscribeableViewNode<
private onNodesCheckedStateChanged(e: TreeCheckboxChangeEvent<ViewNode>) {
const prefix = getComparisonStoragePrefix(this.getStorageId());
if (e.items.some(([n]) => n.id?.startsWith(prefix))) {
void this.storeCompareWith(false);
void this.storeCompareWith(false).catch();
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ export class CompareBranchNode extends SubscribeableViewNode<

@log()
clearReviewed() {
void this.storeCompareWith(true);
void this.storeCompareWith(true).catch();
void this.triggerChange();
}

Expand Down
6 changes: 3 additions & 3 deletions src/views/nodes/compareResultsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class CompareResultsNode extends SubscribeableViewNode<
// If this is a new comparison, save it
if (this._storedAt === 0) {
this._storedAt = Date.now();
void this.store(true);
void this.store(true).catch();
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ export class CompareResultsNode extends SubscribeableViewNode<
private onNodesCheckedStateChanged(e: TreeCheckboxChangeEvent<ViewNode>) {
const prefix = getComparisonStoragePrefix(this.getStorageId());
if (e.items.some(([n]) => n.id?.startsWith(prefix))) {
void this.store(true);
void this.store(true).catch();
}
}

Expand Down Expand Up @@ -252,7 +252,7 @@ export class CompareResultsNode extends SubscribeableViewNode<
@log()
clearReviewed() {
resetComparisonCheckedFiles(this.view, this.getStorageId());
void this.store();
void this.store().catch();
}

@log()
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/launchpadViewGroupingNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class LaunchpadViewGroupingNode<TChild extends ViewNode = ViewNode> exten
storedExpandedGroups.splice(storedExpandedGroups.indexOf(this.group), 1);
}

void this.view.container.storage.store('launchpadView:groups:expanded', storedExpandedGroups);
void this.view.container.storage.store('launchpadView:groups:expanded', storedExpandedGroups).catch();
}
}
}
2 changes: 1 addition & 1 deletion src/views/nodes/searchResultsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SearchResultsNode extends ViewNode<'search-results', SearchAndCompa
// If this is a new search, save it
if (this._storedAt === 0) {
this._storedAt = Date.now();
void this.store(true);
void this.store(true).catch();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/viewBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export abstract class ViewBase<

protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
if (e.visible) {
void this.container.usage.track(`${this.trackingFeature}:shown`);
void this.container.usage.track(`${this.trackingFeature}:shown`).catch();
}

this._onDidChangeVisibility.fire(e);
Expand Down
6 changes: 3 additions & 3 deletions src/views/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Views implements Disposable {
set lastSelectedScmGroupedView(type: GroupableTreeViewTypes | undefined) {
this._lastSelectedScmGroupedView = type;
void setContext('gitlens:views:scm:grouped:view', type);
void this.container.storage.storeWorkspace('views:scm:grouped:selected', type);
void this.container.storage.storeWorkspace('views:scm:grouped:selected', type).catch();
}

private _scmGroupedView: ScmGroupedView | undefined;
Expand Down Expand Up @@ -294,12 +294,12 @@ export class Views implements Disposable {

registerCommand('gitlens.views.scm.grouped.welcome.dismiss', () => {
this._welcomeDismissed = true;
void this.container.storage.store('views:scm:grouped:welcome:dismissed', true);
void this.container.storage.store('views:scm:grouped:welcome:dismissed', true).catch();
this.updateScmGroupedViewsRegistration();
}),
registerCommand('gitlens.views.scm.grouped.welcome.restore', async () => {
this._welcomeDismissed = true;
void this.container.storage.store('views:scm:grouped:welcome:dismissed', true);
void this.container.storage.store('views:scm:grouped:welcome:dismissed', true).catch();
await updateScmGroupedViewsInConfig(new Set());
}),
];
Expand Down
14 changes: 6 additions & 8 deletions src/webviews/commitDetails/commitDetailsWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,10 +1616,9 @@ export class CommitDetailsWebviewProvider
preferences.autolinksExpanded != null &&
this._context.preferences?.autolinksExpanded !== preferences.autolinksExpanded
) {
void this.container.storage.storeWorkspace(
'views:commitDetails:autolinksExpanded',
preferences.autolinksExpanded,
);
void this.container.storage
.storeWorkspace('views:commitDetails:autolinksExpanded', preferences.autolinksExpanded)
.catch();

changes.autolinksExpanded = preferences.autolinksExpanded;
}
Expand All @@ -1628,10 +1627,9 @@ export class CommitDetailsWebviewProvider
preferences.pullRequestExpanded != null &&
this._context.preferences?.pullRequestExpanded !== preferences.pullRequestExpanded
) {
void this.container.storage.storeWorkspace(
'views:commitDetails:pullRequestExpanded',
preferences.pullRequestExpanded,
);
void this.container.storage
.storeWorkspace('views:commitDetails:pullRequestExpanded', preferences.pullRequestExpanded)
.catch();

changes.pullRequestExpanded = preferences.pullRequestExpanded;
}
Expand Down
10 changes: 5 additions & 5 deletions src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,31 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
const collapsed = this.container.storage.get('home:sections:collapsed');
if (collapsed == null) {
if (params.collapsed === true) {
void this.container.storage.store('home:sections:collapsed', [params.section]);
void this.container.storage.store('home:sections:collapsed', [params.section]).catch();
}
return;
}

const idx = collapsed.indexOf(params.section);
if (params.collapsed === true) {
if (idx === -1) {
void this.container.storage.store('home:sections:collapsed', [...collapsed, params.section]);
void this.container.storage.store('home:sections:collapsed', [...collapsed, params.section]).catch();
}

return;
}

if (idx !== -1) {
collapsed.splice(idx, 1);
void this.container.storage.store('home:sections:collapsed', collapsed);
void this.container.storage.store('home:sections:collapsed', collapsed).catch();
}
}

private dismissWalkthrough() {
const dismissed = this.container.storage.get('home:walkthrough:dismissed');
if (!dismissed) {
void this.container.storage.store('home:walkthrough:dismissed', true);
void this.container.usage.track('home:walkthrough:dismissed');
void this.container.storage.store('home:walkthrough:dismissed', true).catch();
void this.container.usage.track('home:walkthrough:dismissed').catch();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/webviews/rebase/rebaseEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl

@debug<RebaseEditorProvider['resolveCustomTextEditor']>({ args: { 1: false, 2: false } })
async resolveCustomTextEditor(document: TextDocument, panel: WebviewPanel, _token: CancellationToken) {
void this.container.usage.track(`rebaseEditor:shown`);
void this.container.usage.track(`rebaseEditor:shown`).catch();

const repoPath = normalizePath(Uri.joinPath(document.uri, '..', '..', '..').fsPath);
const repo = this.container.git.getRepository(repoPath);
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/webviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class WebviewController<
}

if (visible) {
void this.container.usage.track(`${this.descriptor.trackingFeature}:shown`);
void this.container.usage.track(`${this.descriptor.trackingFeature}:shown`).catch();

setContextKeys(this.descriptor.contextKeyPrefix);
if (active != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/webviewsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class WebviewsController implements Disposable {
if (!(await ensurePlusFeaturesEnabled())) return;
}

void container.usage.track(`${descriptor.trackingFeature}:shown`);
void container.usage.track(`${descriptor.trackingFeature}:shown`).catch();

let column = options?.column ?? descriptor.column ?? ViewColumn.Beside;
// Only try to open beside if there is an active tab
Expand Down

0 comments on commit 4d2e632

Please sign in to comment.