mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
99 stars 46 forks source link

Mojo::Pg waste actual error information while error occured in transaction #31

Closed avkhozov closed 8 years ago

avkhozov commented 8 years ago

Issue was already described here https://groups.google.com/d/msg/mojolicious/AJIqhNAOtCo/Z6obMJLOCAAJ

If error occured in transaction, $db->dbh do rollback and clear state, so $db->dbh->err and similar return nothing.

$ cat app.pl
#!/usr/bin/perl -l

use Mojo::Pg;

my $pg = Mojo::Pg->new('postgresql://and@/test');

my $db = $pg->db;

eval {
  my $tx = $db->begin;

  $db->query('table x');
  $db->query('table y');

  $tx->commit;
};
if ($@) {
  print 'E1: ' .$db->dbh->errstr;
  print 'E2: ' .$db->dbh->err;
  print 'E2: ' .$db->dbh->state;
  print $@;
}
$ perl app.pl
E1: 
E2: 
E2: 
DBD::Pg::st execute failed: ERROR:  relation "x" does not exist
LINE 1: table x
              ^ at app.pl line 12.

$ 

Expected behavior

I think there is any way to get errors from dbh related to $db->query, but not for $db->dbh->rollback. Like for non-blocking case, where $sth always available, even for query with errors.

Actual behavior

No information about error

kraih commented 8 years ago

I'm afraid it looks like this issue has the same problem your original post to the mailing-list had, which is that nobody understands it. I can't even say if this is meant as a bug report or feature request. Please be more specific about what exactly it is you want.

avkhozov commented 8 years ago

I don't know what type of this issue (bug or feature request). Rather, this is a feature request.

I want to get ability to get error code from last query in transaction. But I can't because Mojo::Transaction do rollback when $tx out of scope. (https://github.com/kraih/mojo-pg/blob/b43526e1612d690db1cde8155d70b558389b24f5/lib/Mojo/Pg/Transaction.pm#L8)

kraih commented 8 years ago

Sorry, but i'm afraid i can't work with the information you've provided. Perhaps you should consider making a patch and discussing it on the mailing-list or IRC.