Skip to content

Commit 91cb5da

Browse files
committed
refactor(feedback): use shared toError + extend ValidationError
Per Hweinstock's review: - handleFeedback / useFeedbackFlow: replace the local `err instanceof Error ? err : new Error(String(err))` pattern with `toError(err)` from src/lib/errors/types.ts. - FeedbackValidationError: extend `ValidationError` from src/lib/errors/types.ts so the shared error classification helpers treat it as a user error, which means telemetry's classifyError(err)/isUserError(err) will set error_source: 'user' on failure metrics for invalid screenshots / empty messages.
1 parent 90dbe0c commit 91cb5da

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/cli/commands/feedback/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toError } from '../../../lib/errors/types';
12
import { submitFeedback } from '../../operations/feedback';
23
import type { FeedbackSubmissionResult } from '../../operations/feedback';
34
import { promptForConsent } from './consent-prompt';
@@ -23,6 +24,6 @@ export async function handleFeedback(message: string, options: FeedbackOptions):
2324
});
2425
return { kind: 'submitted', result };
2526
} catch (err) {
26-
return { kind: 'error', error: err instanceof Error ? err : new Error(String(err)) };
27+
return { kind: 'error', error: toError(err) };
2728
}
2829
}

src/cli/operations/feedback/submit-feedback.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ValidationError } from '../../../lib/errors/types';
12
import { PACKAGE_VERSION } from '../../constants';
23
import { fetchPresignedUrl, submitForm, uploadFileToS3 } from './aperture-client';
34
import { buildFeedbackPayload, buildUserAgent } from './build-payload';
@@ -14,10 +15,15 @@ import * as fs from 'node:fs/promises';
1415
import * as os from 'node:os';
1516
import * as path from 'node:path';
1617

17-
export class FeedbackValidationError extends Error {
18+
/**
19+
* Thrown for any user-supplied input the feedback command refuses to send to
20+
* Aperture (empty/oversized message, missing/oversized/wrong-type screenshot).
21+
* Extends the shared `ValidationError` so telemetry classifies it as a user
22+
* error rather than a service/client failure.
23+
*/
24+
export class FeedbackValidationError extends ValidationError {
1825
constructor(message: string) {
1926
super(message);
20-
this.name = 'FeedbackValidationError';
2127
}
2228
}
2329

src/cli/tui/screens/feedback/useFeedbackFlow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toError } from '../../../../lib/errors/types';
12
import { submitFeedback, validateFeedbackMessage, validateScreenshotPath } from '../../../operations/feedback';
23
import type { FeedbackSubmissionResult } from '../../../operations/feedback';
34
import { withCommandRunTelemetry } from '../../../telemetry/cli-command-run';
@@ -92,7 +93,7 @@ export function useFeedbackFlow(options: UseFeedbackFlowOptions = {}) {
9293
});
9394
return { success: true, submission };
9495
} catch (err) {
95-
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
96+
return { success: false, error: toError(err) };
9697
}
9798
}
9899
);

0 commit comments

Comments
 (0)