fix: classify MCP SQL query errors as expected (#285)

This commit is contained in:
Andrey Avtomonov 2026-06-10 11:42:31 +02:00 committed by GitHub
parent b076431b0a
commit 036a745fc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 226 additions and 10 deletions

View file

@ -1,6 +1,7 @@
import { inspect } from 'node:util';
import { getKtxCliPackageInfo, type KtxCliIo, type KtxCliPackageInfo } from '../cli-runtime.js';
import { KtxExpectedError } from '../errors.js';
import { buildCommonEnvelope } from './events.js';
import { trackTelemetryException } from './emitter.js';
import { computeTelemetryProjectId, loadTelemetryIdentity } from './identity.js';
@ -39,6 +40,17 @@ function consumeHandledPrimitive(value: unknown): boolean {
return true;
}
/**
* Expected operational errors are surfaced to the caller and recorded by the
* outcome-tagged telemetry events; they are not ktx faults, so they never reach
* Error Tracking. ktx marks these with KtxExpectedError at the site that knows
* the rejection is expected the classification is never inferred globally from
* a generic error type, which would also swallow internal/fatal faults.
*/
function isExpectedError(error: unknown): boolean {
return error instanceof KtxExpectedError;
}
function shouldSkipAsAlreadyReported(error: unknown, handled: boolean): boolean {
if ((typeof error === 'object' || typeof error === 'function') && error !== null) {
if (reportedObjects.has(error)) {
@ -151,6 +163,9 @@ export async function reportException(input: {
redactionSecrets?: ReadonlyArray<string>;
}): Promise<void> {
try {
if (isExpectedError(input.error)) {
return;
}
if (shouldSkipAsAlreadyReported(input.error, input.context.handled)) {
return;
}