Skip to content

Commit

Permalink
Postgres, fix translation tests for some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseChavez committed Jan 22, 2025
1 parent 3b0f6d4 commit 44e7775
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/arjdbc/postgresql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ def translate_exception(exception, message:, sql:, binds:)

# TODO: Can we base these on an error code of some kind?
case exception.message
when /could not create unique index/
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds, connection_pool: @pool)
when /duplicate key value violates unique constraint/
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds)
when /violates not-null constraint/
Expand All @@ -757,7 +759,9 @@ def translate_exception(exception, message:, sql:, binds:)
::ActiveRecord::LockWaitTimeout.new(message, sql: sql, binds: binds)
when /canceling statement/ # This needs to come after lock timeout because the lock timeout message also contains "canceling statement"
::ActiveRecord::QueryCanceled.new(message, sql: sql, binds: binds)
when /relation "animals" does not exist/i
when /relation .* does not exist/i
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
when /syntax error at or near/i
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
else
super
Expand Down

0 comments on commit 44e7775

Please sign in to comment.