-
Notifications
You must be signed in to change notification settings - Fork 324
Open
Description
Hello and thank you for your time and dedication to postgress-js.
The current error handling implementation uses Object.assign to dynamically add properties to error objects (see errors.js). While the README mentions following the PostgreSQL error format, it doesn't document:
- Which property contains the error code
- The complete structure of error properties
- How to properly type-check these errors in TypeScript
Suggestions
1. Enhanced Documentation
Document the complete error object structure, including:
- Available properties (code, message, detail, hint, etc.)
- Which properties are guaranteed vs optional
- Examples of accessing error information
2. Class-Based Error Types
Consider replacing Object.assign with proper error classes:
class PostgresError extends Error {
code: string;
severity: string;
detail?: string;
hint?: string;
// ... other well-defined properties
}I know there is already a PostgressError extending error, but it is not clear what it is use for (I only saw one or two references in the entire codebase) and everything else is just Error.generic which has all the problems I mentioned.
Benefits:
- Better TypeScript autocomplete and type safety
- Clear API surface for error handling
- Improved developer experience
This would significantly improve the TypeScript developer experience.
Metadata
Metadata
Assignees
Labels
No labels