From ad871532ed1c5f515ffde5bc8f46186a179124bf Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Sat, 3 Aug 2019 00:48:07 -0700 Subject: [PATCH] ignore unrecognized URIs If a document has a URI other than `git:` (such as `comment:`, `https:`, etc., which occur in new experimental Sourcegraph features), the following error appears in the browser JS console: ``` Uncaught (in promise) Error: unrecognized URI: "comment://2" (supported URI schemes: git) ``` This change suppresses that error by skipping the attempt to decorate such files. --- src/extension.ts | 3 +++ src/uri.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 828fc31..e1c3629 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,6 +23,9 @@ export function activate(): void { } const uri = resolveURI(editor.document.uri) + if (!uri) { + return + } const threads = await fetchDiscussionThreads({ first: 10000, diff --git a/src/uri.ts b/src/uri.ts index d4395c7..0103a6a 100644 --- a/src/uri.ts +++ b/src/uri.ts @@ -2,7 +2,7 @@ * Resolve a URI of the forms git://github.com/owner/repo?rev#path and file:///path to an absolute reference, using * the given base (root) URI. */ -export function resolveURI(uri: string): { repo: string; rev: string; path: string } { +export function resolveURI(uri: string): { repo: string; rev: string; path: string } | null { const url = new URL(uri) if (url.protocol === 'git:') { return { @@ -11,5 +11,5 @@ export function resolveURI(uri: string): { repo: string; rev: string; path: stri path: url.hash.slice(1), } } - throw new Error(`unrecognized URI: ${JSON.stringify(uri)} (supported URI schemes: git)`) + return null }