From ec8de4eb45198dba5044a5206870ffd25e4c7ab3 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 20 Nov 2019 10:53:20 +0100 Subject: [PATCH] git: better uri parsing error message --- extensions/git/src/uri.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/git/src/uri.ts b/extensions/git/src/uri.ts index e2dc44088bd..3ef84a642f7 100644 --- a/extensions/git/src/uri.ts +++ b/extensions/git/src/uri.ts @@ -17,7 +17,21 @@ export function isGitUri(uri: Uri): boolean { } export function fromGitUri(uri: Uri): GitUriParams { - return qs.parse(uri.query) as any; + const result = qs.parse(uri.query) as any; + + if (!result) { + throw new Error('Invalid git URI: empty query'); + } + + if (typeof result.path !== 'string') { + throw new Error('Invalid git URI: missing path'); + } + + if (typeof result.ref !== 'string') { + throw new Error('Invalid git URI: missing ref'); + } + + return result; } export interface GitUriOptions {