Skip to content

Commit b78918a

Browse files
committed
feat(cli): pass error code as Sentry tag on captured exceptions
Adds the error code as an `error.code` tag to Sentry exceptions, matching the v1 SentryClient behavior. The code is resolved via resolveErrorCode in both reportError and TaskContextAdapter. Made-with: Cursor
1 parent e9ec282 commit b78918a

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/cli/cli-v2/src/context/adapter/TaskContextAdapter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type Finishable,
66
type InteractiveTaskContext,
77
type PosthogEvent,
8+
resolveErrorCode,
89
type Startable,
910
TaskAbortSignal,
1011
type TaskContext,
@@ -68,8 +69,9 @@ export class TaskContextAdapter implements TaskContext {
6869
reportError(this.context, error ?? new Error(message), options);
6970
}
7071

71-
public captureException(error: unknown, _code?: CliError.Code): void {
72-
this.context.telemetry.captureException(error);
72+
public captureException(error: unknown, code?: CliError.Code): void {
73+
const errorCode = resolveErrorCode(error, code) ?? "INTERNAL_ERROR";
74+
this.context.telemetry.captureException(error, { errorCode });
7375
}
7476

7577
private getFullErrorMessage(message?: string, error?: unknown): string | undefined {

packages/cli/cli-v2/src/context/withContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function reportError(context: Context, error: unknown, options?: { code?:
114114
}
115115
const code = resolveErrorCode(error, options?.code) ?? "INTERNAL_ERROR";
116116
if (shouldReportToSentry(code)) {
117-
context.telemetry.captureException(error);
117+
context.telemetry.captureException(error, { errorCode: code });
118118
}
119119
context.telemetry.sendLifecycleEvent({
120120
status: "error",

packages/cli/cli-v2/src/telemetry/TelemetryClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ export class TelemetryClient {
105105
* The caller is responsible for deciding which errors are worth reporting
106106
* (see `shouldReportToSentry` in withContext.ts).
107107
*/
108-
public captureException(error: unknown): void {
108+
public captureException(error: unknown, { errorCode }: { errorCode: string }): void {
109109
if (this.sentry === undefined) {
110110
return;
111111
}
112112
try {
113113
this.sentry.captureException(error, {
114114
captureContext: {
115115
user: { id: this.distinctId },
116-
tags: { ...this.baseTags, ...this.accumulatedTags }
116+
tags: { ...this.baseTags, ...this.accumulatedTags, "error.code": errorCode }
117117
}
118118
});
119119
} catch {

0 commit comments

Comments
 (0)