mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
fix: classify MCP SQL query errors as expected (#285)
This commit is contained in:
parent
b076431b0a
commit
036a745fc1
6 changed files with 226 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue