Sfoglia il codice sorgente

Adds better provider error handling

main
Eric Amodio 2 anni fa
parent
commit
11da2efc97
2 ha cambiato i file con 25 aggiunte e 20 eliminazioni
  1. +10
    -2
      src/errors.ts
  2. +15
    -18
      src/git/gitProviderService.ts

+ 10
- 2
src/errors.ts Vedi File

@ -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 Vedi File

@ -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);

Caricamento…
Annulla
Salva