Path: blob/main/extensions/copilot/src/platform/remoteSearch/common/codeOrDocsSearchErrors.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45export const enum SearchRepoErrorType {6missingInaccessibleRepoOrg = 'ERROR_TYPE_MISSING_INACCESSIBLE_REPO_ORG',7docsEmbeddingsUnavailable = 'ERROR_TYPE_DOCS_EMBEDDINGS_UNAVAILABLE',8notIndexed = 'ERROR_TYPE_NOT_INDEXED',9}1011export const enum SearchErrorType {12maxRetriesExceeded = 'ERROR_TYPE_MAX_RETRIES_EXCEEDED',13noAccessToEndpoint = 'ERROR_TYPE_NO_ACCESS_TO_ENDPOINT',14}1516export class CodeOrDocsSearchRepoError extends Error {17constructor(readonly repo: string, message?: string) {18super(message);19}20}2122/**23* This error is thrown when the repository is not accessible to the user. This might be because the user24* does not have access to the repository or the token does not have the OAuth scope (repo) to access the repository.25*/26export class InaccessibleRepoOrgError extends CodeOrDocsSearchRepoError {27override name = SearchRepoErrorType.missingInaccessibleRepoOrg;28}2930/**31* This error is thrown when the docs embeddings are not available for the given repository.32* NOTE: For our usecases, this is basically the same thing as NotIndexedError.33*/34export class EmbeddingsUnavailableError extends CodeOrDocsSearchRepoError {35override name = SearchRepoErrorType.docsEmbeddingsUnavailable;36}3738/**39* This error is thrown when the repository is not indexed entirely including when the embeddings are not available.40* NOTE: For our usecases, this is basically the same thing as EmbeddingsUnavailableError.41*/42export class NotIndexedError extends CodeOrDocsSearchRepoError {43override name = SearchRepoErrorType.notIndexed;44}4546/**47* This error is not thrown by the endpoint but is thrown by the client when the max retries are exceeded.48*/49export class MaxRetriesExceededError extends Error {50override name = SearchErrorType.maxRetriesExceeded;51}5253/**54* This error is not thrown by the endpoint but is thrown by the client when the code or docs search endpoint is not accessible.55* This is usually because of a feature flag that is not enabled for this user.56*/57export class NoAccessToEndpointError extends Error {58override name = SearchErrorType.noAccessToEndpoint;59}6061export function constructSearchRepoError({ error, message, repo }: { error: string; message: string; repo: string }): CodeOrDocsSearchRepoError {62switch (error) {63case SearchRepoErrorType.missingInaccessibleRepoOrg:64return new InaccessibleRepoOrgError(repo, message);65case SearchRepoErrorType.docsEmbeddingsUnavailable:66return new EmbeddingsUnavailableError(repo, message);67case SearchRepoErrorType.notIndexed:68return new NotIndexedError(repo, message);69default:70return new CodeOrDocsSearchRepoError(repo, message);71}72}7374export function constructSearchError({ error, message }: { error: string; message: string }): Error {75switch (error) {76case SearchErrorType.maxRetriesExceeded:77return new MaxRetriesExceededError(message);78case SearchErrorType.noAccessToEndpoint:79return new NoAccessToEndpointError(message);80default:81return new Error(message);82}83}848586