@contember/database 2.2.0-alpha.17 → 2.2.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/development/index.cjs +1 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +2 -1
  5. package/dist/development/src/client/AcquiredConnection.cjs +2 -0
  6. package/dist/development/src/client/AcquiredConnection.cjs.map +1 -1
  7. package/dist/development/src/client/AcquiredConnection.js +3 -1
  8. package/dist/development/src/client/AcquiredConnection.js.map +1 -1
  9. package/dist/development/src/client/errors.cjs +6 -1
  10. package/dist/development/src/client/errors.cjs.map +1 -1
  11. package/dist/development/src/client/errors.js +6 -1
  12. package/dist/development/src/client/errors.js.map +1 -1
  13. package/dist/development/src/utils/pgClientFactory.cjs.map +1 -1
  14. package/dist/development/src/utils/pgClientFactory.js.map +1 -1
  15. package/dist/production/index.cjs +1 -0
  16. package/dist/production/index.cjs.map +1 -1
  17. package/dist/production/index.js +2 -1
  18. package/dist/production/src/client/AcquiredConnection.cjs +2 -0
  19. package/dist/production/src/client/AcquiredConnection.cjs.map +1 -1
  20. package/dist/production/src/client/AcquiredConnection.js +3 -1
  21. package/dist/production/src/client/AcquiredConnection.js.map +1 -1
  22. package/dist/production/src/client/errors.cjs +6 -1
  23. package/dist/production/src/client/errors.cjs.map +1 -1
  24. package/dist/production/src/client/errors.js +6 -1
  25. package/dist/production/src/client/errors.js.map +1 -1
  26. package/dist/production/src/utils/pgClientFactory.cjs.map +1 -1
  27. package/dist/production/src/utils/pgClientFactory.js.map +1 -1
  28. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  29. package/dist/types/client/AcquiredConnection.d.ts.map +1 -1
  30. package/dist/types/client/PgClient.d.ts +1 -1
  31. package/dist/types/client/PgClient.d.ts.map +1 -1
  32. package/dist/types/client/errors.d.ts +2 -0
  33. package/dist/types/client/errors.d.ts.map +1 -1
  34. package/dist/types/tsconfig.tsbuildinfo +1 -1
  35. package/dist/types/utils/pgClientFactory.d.ts +1 -2
  36. package/dist/types/utils/pgClientFactory.d.ts.map +1 -1
  37. package/package.json +4 -3
  38. package/src/client/AcquiredConnection.ts +3 -0
  39. package/src/client/PgClient.ts +2 -1
  40. package/src/client/errors.ts +9 -3
  41. package/src/utils/pgClientFactory.ts +1 -3
  42. package/tests/cases/unit/acquiredConnection.test.ts +40 -0
@@ -167,3 +167,43 @@ for (
167
167
  await expect(connection.query('SELECT 1')).rejects.toThrow(InvalidDataError)
168
168
  })
169
169
  }
170
+
171
+ it('puts the PostgreSQL detail and hint of a failed query into the error message', async () => {
172
+ const connection = new AcquiredConnection(
173
+ createPgClientMock(async () => {
174
+ throw Object.assign(new Error('cannot drop column otp_uri of table person because other objects depend on it'), {
175
+ code: '2BP01',
176
+ detail: 'view app.person_otp depends on column otp_uri of table person',
177
+ hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
178
+ })
179
+ }),
180
+ new EventManager(),
181
+ )
182
+
183
+ const error = await connection.query('ALTER TABLE person DROP COLUMN otp_uri').catch(e => e)
184
+ if (!(error instanceof QueryError)) {
185
+ throw error
186
+ }
187
+ expect(error.message).toBe(
188
+ 'Database query error: cannot drop column otp_uri of table person because other objects depend on it\n'
189
+ + 'Detail: view app.person_otp depends on column otp_uri of table person\n'
190
+ + 'Hint: Use DROP ... CASCADE to drop the dependent objects too.\n'
191
+ + 'SQL: ALTER TABLE person DROP COLUMN otp_uri\n'
192
+ + 'parameters: ',
193
+ )
194
+ })
195
+
196
+ it('leaves detail and hint out of the error message when PostgreSQL sends none', async () => {
197
+ const connection = new AcquiredConnection(
198
+ createPgClientMock(async () => {
199
+ throw Object.assign(new Error('relation "missing" does not exist'), { code: '42P01', detail: undefined, hint: undefined })
200
+ }),
201
+ new EventManager(),
202
+ )
203
+
204
+ const error = await connection.query('SELECT * FROM missing').catch(e => e)
205
+ if (!(error instanceof QueryError)) {
206
+ throw error
207
+ }
208
+ expect(error.message).toBe('Database query error: relation "missing" does not exist\nSQL: SELECT * FROM missing\nparameters: ')
209
+ })