Skip to content

Commit 84b7387

Browse files
authored
Avoid throwing and handling exception is avoidable (#6484)
Fixes #6480
1 parent a53fe0d commit 84b7387

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/common/uri.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export interface PRUriParams {
4141
}
4242

4343
export function fromPRUri(uri: vscode.Uri): PRUriParams | undefined {
44+
if (uri.query === '') {
45+
return undefined;
46+
}
4447
try {
4548
return JSON.parse(uri.query) as PRUriParams;
4649
} catch (e) { }
@@ -51,6 +54,9 @@ export interface PRNodeUriParams {
5154
}
5255

5356
export function fromPRNodeUri(uri: vscode.Uri): PRNodeUriParams | undefined {
57+
if (uri.query === '') {
58+
return undefined;
59+
}
5460
try {
5561
return JSON.parse(uri.query) as PRNodeUriParams;
5662
} catch (e) { }
@@ -63,6 +69,9 @@ export interface GitHubUriParams {
6369
isEmpty?: boolean;
6470
}
6571
export function fromGitHubURI(uri: vscode.Uri): GitHubUriParams | undefined {
72+
if (uri.query === '') {
73+
return undefined;
74+
}
6675
try {
6776
return JSON.parse(uri.query) as GitHubUriParams;
6877
} catch (e) { }
@@ -338,8 +347,11 @@ export function toResourceUri(uri: vscode.Uri, prNumber: number, fileName: strin
338347
}
339348

340349
export function fromFileChangeNodeUri(uri: vscode.Uri): FileChangeNodeUriParams | undefined {
350+
if (uri.query === '') {
351+
return undefined;
352+
}
341353
try {
342-
return uri.query ? JSON.parse(uri.query) as FileChangeNodeUriParams : undefined;
354+
return JSON.parse(uri.query) as FileChangeNodeUriParams;
343355
} catch (e) { }
344356
}
345357

0 commit comments

Comments
 (0)