-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/improved errors #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/improved errors #547
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add shared pg-error-format utility in @pgpmjs/types with extractPgErrorFields, formatPgErrorFields, and formatPgError functions - Enhance pgpm/core migrate/utils/transaction.ts with extended PG error fields - Enhance pgpm/core migrate/client.ts with extended PG error fields - Add opt-in enhanced errors to PgTestClient via enhancedErrors option or PGSQL_TEST_ENHANCED_ERRORS env var - Improve seed error handling in pgsql-test connect.ts - Add comprehensive tests for error formatting utilities This provides better debugging information for PostgreSQL errors including: - detail, hint, where, position fields - schema, table, column, dataType, constraint fields - query and values context when available
Enhanced PostgreSQL error messages are now enabled by default for better debugging experience. Can be disabled via enhancedErrors: false option or PGSQL_TEST_ENHANCED_ERRORS=0 environment variable.
- Remove PGSQL_TEST_ENHANCED_ERRORS env var check (enhanced errors now always default to true, can be disabled via enhancedErrors: false option) - Add tests for nested EXECUTE migration errors with full call stack context - Add tests for constraint violations in nested EXECUTE - Add tests for transaction aborted errors with context
Add Jest snapshots showing the exact formatted output for: 1. JSON/JSONB type mismatch error (simple case) 2. Nested EXECUTE migration error with full PL/pgSQL call stack
Remove all mock error objects and replace with real database tests that: - Create actual tables with constraints - Trigger real PostgreSQL errors (JSON type mismatch, unique violations, FK violations, etc.) - Use getConnections() and PgTestClient for proper test isolation - Include snapshot tests for error message formatting Tests will generate snapshots in CI where PostgreSQL is available.
Snapshots generated from actual PostgreSQL errors in CI: 1. JSON/JSONB type mismatch error 2. Unique constraint violation error 3. Foreign key violation error 4. Undefined table error 5. Nested EXECUTE error with PL/pgSQL call stack 6. Constraint violation inside nested EXECUTE
…cedures Use GET STACKED DIAGNOSTICS to capture all error fields (sqlstate, message, detail, hint, context, schema, table, column, constraint, datatype) when EXECUTE fails, and re-raise with RAISE EXCEPTION USING to preserve them. This ensures the Node.js pg library receives the full error context, which can then be formatted by formatPgError for enhanced error messages.
The GET STACKED DIAGNOSTICS fix now preserves PostgreSQL error context: - code: error codes like 42P01, 23505, 22P02 - detail: constraint violation details - schema/table/constraint: object identifiers - where: full PL/pgSQL call stack - internalQuery: the actual failing SQL statement
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.