Skip to content

Commit 328f8ef

Browse files
committed
Handles potential errors when retrieving the active repository
Addresses a scenario where the active repository cannot be retrieved, which commonly occurs when the currently open file is not part of a repository. A try-catch block is added to gracefully handle this situation, logging the error and setting the active repository to undefined. (#4224)
1 parent 8306be1 commit 328f8ef

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/commands/quickCommand.steps.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,16 @@ export async function* pickRepositoryStep<
16161616
state.repo = Container.instance.git.getRepository(state.repo);
16171617
if (state.repo != null) return state.repo;
16181618
}
1619-
const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor());
1619+
let active;
1620+
try {
1621+
active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor());
1622+
} catch (ex) {
1623+
Logger.log(
1624+
'pickRepositoryStep: failed to get active repository. Normally it happens when the currently open file does not belong to a repository',
1625+
ex,
1626+
);
1627+
active = undefined;
1628+
}
16201629

16211630
const step = createPickStep<RepositoryQuickPickItem>({
16221631
title: context.title,

0 commit comments

Comments
 (0)