-
Notifications
You must be signed in to change notification settings - Fork 0
Implement structured error logging with error codes #17
Copy link
Copy link
Open
Labels
Description
Problem
Error handling across the codebase is inconsistent:
- Some
try-catchblocks silently swallow errors (especially JSON parsing in ingestion) - API routes return generic "Unexpected server error" with no error code
- No structured logging format — errors are logged as raw strings or not at all
- Debugging production issues requires reading source code to trace error origins
Proposed Solution
1. Error Code Registry
// lib/opentrust/errors.ts
export enum ErrorCode {
DB_CONNECTION_FAILED = "DB_CONNECTION_FAILED",
DB_QUERY_FAILED = "DB_QUERY_FAILED",
AUTH_INVALID_CREDENTIALS = "AUTH_INVALID_CREDENTIALS",
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
VALIDATION_FAILED = "VALIDATION_FAILED",
INGESTION_PARSE_ERROR = "INGESTION_PARSE_ERROR",
MEMORY_NOT_FOUND = "MEMORY_NOT_FOUND",
SEARCH_QUERY_INVALID = "SEARCH_QUERY_INVALID",
// ...
}2. Structured Logger
// lib/opentrust/logger.ts
logger.error({
code: ErrorCode.INGESTION_PARSE_ERROR,
message: "Failed to parse session JSON",
context: { sessionId, filePath },
error: originalError,
});3. Audit Trail
- Errors logged with timestamp, code, context, and stack trace
- Replace all silent
catchblocks with explicit logging
Acceptance Criteria
- Error code enum covers all known error categories
- Structured logger utility created with
error,warn,infolevels - All
try-catchblocks use the structured logger (no silent swallowing) - API error responses include error codes
- Unit tests for the logger utility
🤖 Generated with Claude Code
Reactions are currently unavailable