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