Skip to content

Commit 4a9b189

Browse files
committed
telemetry: Move common errors to shared folder
1 parent 32a7bd4 commit 4a9b189

File tree

8 files changed

+38
-35
lines changed

8 files changed

+38
-35
lines changed

packages/amazonq/test/unit/amazonqFeatureDev/util/files.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
maxRepoSizeBytes,
1212
} from 'aws-core-vscode/amazonqFeatureDev'
1313
import { assertTelemetry, getWorkspaceFolder, TestFolder } from 'aws-core-vscode/test'
14-
import { fs, AmazonqCreateUpload, ZipStream } from 'aws-core-vscode/shared'
14+
import { fs, AmazonqCreateUpload, ZipStream, ContentLengthError } from 'aws-core-vscode/shared'
1515
import { MetricName, Span } from 'aws-core-vscode/telemetry'
1616
import sinon from 'sinon'
1717
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
18-
import { ContentLengthError, CurrentWsFolders } from 'aws-core-vscode/amazonq'
18+
import { CurrentWsFolders } from 'aws-core-vscode/amazonq'
1919
import path from 'path'
2020

2121
const testDevfilePrepareRepo = async (devfileEnabled: boolean) => {

packages/core/src/amazonq/errors.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@
1111
*/
1212
import { ErrorInformation, ToolkitError } from '../shared/errors'
1313

14-
/**
15-
* Errors extending this class are considered "errors" in service metrics.
16-
*/
17-
export class ClientError extends ToolkitError {
18-
constructor(message: string, info: ErrorInformation = {}) {
19-
super(message, info)
20-
}
21-
}
22-
23-
/**
24-
* Errors extending this class are considered "faults" in service metrics.
25-
*/
26-
export class ServiceError extends ToolkitError {
27-
constructor(message: string, info: ErrorInformation = {}) {
28-
super(message, info)
29-
}
30-
}
31-
3214
/**
3315
* Errors extending this class are considered "LLM failures" in service metrics.
3416
*/
@@ -37,9 +19,3 @@ export class LlmError extends ToolkitError {
3719
super(message, info)
3820
}
3921
}
40-
41-
export class ContentLengthError extends ClientError {
42-
constructor(message: string, info: ErrorInformation = { code: 'ContentLengthError' }) {
43-
super(message, info)
44-
}
45-
}

packages/core/src/amazonq/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export { ExtensionMessage } from '../amazonq/webview/ui/commands'
4444
export { CodeReference } from '../codewhispererChat/view/connector/connector'
4545
export { extractAuthFollowUp } from './util/authUtils'
4646
export { Messenger } from './commons/connector/baseMessenger'
47-
export { ContentLengthError } from './errors'
4847
import { FeatureContext } from '../shared/featureConfig'
4948

5049
/**

packages/core/src/amazonq/util/files.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PrepareRepoFailedError } from '../../amazonqFeatureDev/errors'
1616
import { getLogger } from '../../shared/logger/logger'
1717
import { maxFileSizeBytes } from '../../amazonqFeatureDev/limits'
1818
import { CurrentWsFolders, DeletedFileInfo, NewFileInfo, NewFileZipContents } from '../../amazonqDoc/types'
19-
import { hasCode, ToolkitError } from '../../shared/errors'
19+
import { ContentLengthError, hasCode, ToolkitError } from '../../shared/errors'
2020
import { AmazonqCreateUpload, Span, telemetry as amznTelemetry, telemetry } from '../../shared/telemetry/telemetry'
2121
import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
2222
import { isCodeFile } from '../../shared/filetypes'
@@ -28,7 +28,6 @@ import { ZipStream } from '../../shared/utilities/zipStream'
2828
import { isPresent } from '../../shared/utilities/collectionUtils'
2929
import { AuthUtil } from '../../codewhisperer/util/authUtil'
3030
import { TelemetryHelper } from '../util/telemetryHelper'
31-
import { ContentLengthError } from '../errors'
3231

3332
export const SvgFileExtension = '.svg'
3433

packages/core/src/amazonqDoc/session/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import fs from '../../shared/fs/fs'
3030
import globals from '../../shared/extensionGlobals'
3131
import { extensionVersion } from '../../shared/vscode/env'
3232
import { getLogger } from '../../shared/logger/logger'
33+
import { ContentLengthError as CommonAmazonQContentLengthError } from '../../shared/errors'
3334
import { ContentLengthError } from '../errors'
34-
import { ContentLengthError as CommonAmazonQContentLengthError } from '../../amazonq/errors'
3535

3636
export class Session {
3737
private _state?: SessionState | Omit<SessionState, 'uploadId'>

packages/core/src/amazonqFeatureDev/errors.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
import { featureName, clientErrorMessages, startTaskAssistLimitReachedMessage } from './constants'
77
import { uploadCodeError } from './userFacingText'
88
import { i18n } from '../shared/i18n-helper'
9-
import { ClientError, LlmError, ServiceError, ContentLengthError as SharedContentLengthError } from '../amazonq/errors'
9+
import { LlmError } from '../amazonq/errors'
1010
import { MetricDataResult } from '../amazonq/commons/types'
11-
import { ToolkitError } from '../shared/errors'
11+
import {
12+
ClientError,
13+
ServiceError,
14+
ContentLengthError as CommonContentLengthError,
15+
ToolkitError,
16+
} from '../shared/errors'
1217

1318
export class ConversationIdNotFoundError extends ServiceError {
1419
constructor() {
@@ -104,7 +109,7 @@ export class IllegalStateError extends ServiceError {
104109
}
105110
}
106111

107-
export class ContentLengthError extends SharedContentLengthError {
112+
export class ContentLengthError extends CommonContentLengthError {
108113
constructor() {
109114
super(i18n('AWS.amazonq.featureDev.error.contentLengthError'), { code: ContentLengthError.name })
110115
}

packages/core/src/amazonqFeatureDev/session/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { UpdateAnswerMessage } from '../../amazonq/commons/connector/connectorMe
3333
import { FollowUpTypes } from '../../amazonq/commons/types'
3434
import { SessionConfig } from '../../amazonq/commons/session/sessionConfigFactory'
3535
import { Messenger } from '../../amazonq/commons/connector/baseMessenger'
36-
import { ContentLengthError as CommonAmazonQContentLengthError } from '../../amazonq/errors'
36+
import { ContentLengthError as CommonContentLengthError } from '../../shared/errors'
3737
export class Session {
3838
private _state?: SessionState | Omit<SessionState, 'uploadId'>
3939
private task: string = ''
@@ -159,7 +159,7 @@ export class Session {
159159

160160
return resp.interaction
161161
} catch (e) {
162-
if (e instanceof CommonAmazonQContentLengthError) {
162+
if (e instanceof CommonContentLengthError) {
163163
getLogger().debug(`Content length validation failed: ${e.message}`)
164164
throw new ContentLengthError()
165165
}

packages/core/src/shared/errors.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,30 @@ export class PermissionsError extends ToolkitError {
826826
}
827827
}
828828

829+
/**
830+
* Errors extending this class are considered "errors" in service metrics.
831+
*/
832+
export class ClientError extends ToolkitError {
833+
constructor(message: string, info: ErrorInformation = { code: '400' }) {
834+
super(message, info)
835+
}
836+
}
837+
838+
/**
839+
* Errors extending this class are considered "faults" in service metrics.
840+
*/
841+
export class ServiceError extends ToolkitError {
842+
constructor(message: string, info: ErrorInformation = { code: '500' }) {
843+
super(message, info)
844+
}
845+
}
846+
847+
export class ContentLengthError extends ClientError {
848+
constructor(message: string, info: ErrorInformation = { code: 'ContentLengthError' }) {
849+
super(message, info)
850+
}
851+
}
852+
829853
export function isNetworkError(err?: unknown): err is Error & { code: string } {
830854
if (!(err instanceof Error)) {
831855
return false

0 commit comments

Comments
 (0)