Skip to content
Snippets Groups Projects

feat: show markdown help for missing token

Files
7
@@ -42,7 +42,8 @@ async function nullIf40x<T>(p: Promise<T>) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function handleError(e: any): Promise<never> {
if (e instanceof HelpError) await Help.showMessage(e.message, e.options, HelpMessageSeverity.Warning);
if (e instanceof HelpError)
await Help.showMessage(e.message, e.options, HelpMessageSeverity.Warning);
else if (!(e instanceof vscode.FileSystemError)) logError(e);
throw e;
}
@@ -75,15 +76,26 @@ export class GitLabRemoteFileSystem extends ReadOnlyFileSystem {
*/
static parseUri(uri: vscode.Uri): GitLabRemotePath {
if (uri.scheme !== REMOTE_URI_SCHEME) {
throw new HelpError(`URI is not a GitLab remote. It begins with ${uri.scheme} but it should begin with ${REMOTE_URI_SCHEME}`, { section: README_SECTIONS.REMOTEFS });
throw new HelpError(
`URI is not a GitLab remote. It begins with ${uri.scheme} but it should begin with ${REMOTE_URI_SCHEME}`,
{ section: README_SECTIONS.REMOTEFS },
);
}
const query = new URLSearchParams(uri.query);
const project = query.get('project');
if (!project) throw new HelpError('URI is not a GitLab remote. The URI must contain a project= query parameter', { section: README_SECTIONS.REMOTEFS });
if (!project)
throw new HelpError(
'URI is not a GitLab remote. The URI must contain a project= query parameter',
{ section: README_SECTIONS.REMOTEFS },
);
const ref = query.get('ref');
if (!ref) throw new HelpError('URI is not a GitLab remote. The URI must contain a ref= query parameter', { section: README_SECTIONS.REMOTEFS });
if (!ref)
throw new HelpError(
'URI is not a GitLab remote. The URI must contain a ref= query parameter',
{ section: README_SECTIONS.REMOTEFS },
);
// Find the instance with a matching authority and a subpath that is a
// prefix of the URI's path.
@@ -91,7 +103,11 @@ export class GitLabRemoteFileSystem extends ReadOnlyFileSystem {
.getInstanceUrls()
.map(x => vscode.Uri.parse(x))
.find(x => uri.authority === x.authority && uri.path.startsWith(x.path));
if (!instance) throw new HelpError(`Cannot open ${uri}: missing token for GitLab instance ${uri.authority}`, { section: README_SECTIONS.SETUP });
if (!instance)
throw new HelpError(
`Cannot open ${uri}: missing token for GitLab instance ${uri.authority}`,
{ section: README_SECTIONS.SETUP },
);
// To get the file path, we first remove the instance subpath, then the
// project label.
Loading