浏览代码

Adds better provider error handling

main
Eric Amodio 2 年前
父节点
当前提交
11da2efc97
共有 2 个文件被更改,包括 25 次插入20 次删除
  1. +10
    -2
      src/errors.ts
  2. +15
    -18
      src/git/gitProviderService.ts

+ 10
- 2
src/errors.ts 查看文件

@ -46,8 +46,16 @@ export class AuthenticationError extends Error {
}
export class ProviderNotFoundError extends Error {
constructor(pathOrUri: string | Uri) {
super(`No provider registered for '${typeof pathOrUri === 'string' ? pathOrUri : pathOrUri.toString(true)}'`);
constructor(pathOrUri: string | Uri | undefined) {
super(
`No provider registered for '${
pathOrUri == null
? String(pathOrUri)
: typeof pathOrUri === 'string'
? pathOrUri
: pathOrUri.toString(true)
}'`,
);
Error.captureStackTrace?.(this, ProviderNotFoundError);
}

+ 15
- 18
src/git/gitProviderService.ts 查看文件

@ -26,6 +26,7 @@ import {
WorkspaceState,
} from '../constants';
import type { Container } from '../container';
import { isWeb } from '../env/node/platform';
import { ProviderNotFoundError } from '../errors';
import { Logger } from '../logger';
import { Arrays, debug, gate, Iterables, log, Promises } from '../system';
@ -578,7 +579,20 @@ export class GitProviderService implements Disposable {
}
private getProvider(repoPath: string | Uri): GitProviderResult {
const id = GitProviderService.getProviderId(repoPath);
if (repoPath == null || (typeof repoPath !== 'string' && !this._supportedSchemes.has(repoPath.scheme))) {
debugger;
throw new ProviderNotFoundError(repoPath);
}
let id = !isWeb ? GitProviderId.Git : undefined;
if (typeof repoPath !== 'string' && repoPath.scheme === DocumentSchemes.Virtual) {
if (repoPath.authority.startsWith('github')) {
id = GitProviderId.GitHub;
} else {
throw new ProviderNotFoundError(repoPath);
}
}
if (id == null) throw new ProviderNotFoundError(repoPath);
const provider = this._providers.get(id);
if (provider == null) throw new ProviderNotFoundError(repoPath);
@ -598,23 +612,6 @@ export class GitProviderService implements Disposable {
}
}
static getProviderId(repoPath: string | Uri): GitProviderId {
if (repoPath == null) {
debugger;
throw new Error('Unsupported provider; no repository path');
}
if (typeof repoPath !== 'string' && repoPath.scheme === DocumentSchemes.Virtual) {
if (repoPath.authority.startsWith('github')) {
return GitProviderId.GitHub;
}
throw new Error(`Unsupported provider: ${repoPath.scheme}`);
}
return GitProviderId.Git;
}
@log()
addRemote(repoPath: string | Uri, name: string, url: string): Promise<void> {
const { provider, path } = this.getProvider(repoPath);

正在加载...
取消
保存