refactor(ai_token): Cleaned up error messages - #52
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughEvent streaming now collects per-request failures instead of aborting, mapping errors to standardized failure codes and reporting detailed failure entries; the Postgres adapter extracts DB error codes and reclassifies duplicate-key violations as structured storage errors; proto submodule pointer updated. ChangesPartial-Success Event Streaming with Error Classification
sequenceDiagram
participant Client
participant StreamHandler as streamEvents
participant Storage
participant Sentry
participant ResponseBuilder
Client->>StreamHandler: stream event requests
loop per request
StreamHandler->>Storage: attempt add/process event
alt Storage/error
Storage-->>StreamHandler: throw error
StreamHandler->>StreamHandler: getFailureCode(error)
StreamHandler->>Sentry: add breadcrumb + captureException(eventIndex,idempotencyKey,errorCode)
StreamHandler->>ResponseBuilder: append EventFailure(eventIndex,idempotencyKey,errorCode,message)
else success
StreamHandler->>ResponseBuilder: increment eventsProcessed
end
StreamHandler->>StreamHandler: eventIndex++
end
StreamHandler->>ResponseBuilder: build StreamEventResponse(eventsProcessed, eventsFailed, failures)
ResponseBuilder->>Client: send final response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/routes/gRPC/events/streamEvents.ts`:
- Around line 85-89: The current code assigns raw exception text to
failure.message (in the EventFailure created in streamEvents.ts), which can leak
internal details; instead, map failure.errorCode (from
getFailureCode(innerError)) to a stable public message (e.g., via a helper like
publicMessageForCode(errorCode) with a default "internal server error"), set
failure.message to that stable string, and send the full innerError to Sentry
(captureException) along with context (idempotencyKey, eventIndex, errorCode) so
internal details are recorded but not returned to clients.
- Around line 17-31: getFailureCode currently detects Zod errors by matching
err.name and may propagate raw Zod messages; update it to explicitly import and
check against ZodError (use `err instanceof ZodError`) or ensure callers
normalize ZodError into a domain ValidationError before calling getFailureCode,
and change the code path that maps Zod innerError.message into the failure
payload to instead set a safe, generic validation message (e.g.,
"VALIDATION_FAILED" with a sanitized message) while sending full Zod details to
Sentry/logging; modify getFailureCode and any callers (e.g., streamEvents
handlers) to use the explicit ZodError check and to avoid copying
innerError.message directly into failure.message.
In `@src/storage/adapter/postgres/handlers/addEventUtils.ts`:
- Around line 41-49: The catch currently maps all errors (except SQLSTATE 23505)
to StorageError.transactionFailed, which overrides existing StorageError types;
update the catch in addEventUtils (the block using hasPostgresErrorCode(e,
"23505") and throwing StorageError.transactionFailed) to first detect and
rethrow existing StorageError instances (e.g., via e instanceof StorageError or
a helper isStorageError) so original StorageError.type (like
invalidTimestamp/invalidData) is preserved; only convert non-StorageError
exceptions (and handle 23505 -> StorageError.constraintViolation) into
transactionFailed as before, keeping operationName in the transactionFailed
message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b86c694-1682-41cb-a059-49dfb5341862
⛔ Files ignored due to path filters (1)
src/gen/event/v1/event.tsis excluded by!**/gen/**
📒 Files selected for processing (2)
src/routes/gRPC/events/streamEvents.tssrc/storage/adapter/postgres/handlers/addEventUtils.ts
Summary by CodeRabbit