Skip to content

Commit 54f100b

Browse files
committedDec 18, 2022
Improve error reporting from wrapped DBI methods in Bugzilla::DB
1 parent b6a038d commit 54f100b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎Bugzilla/DB.pm

+20-5
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,23 @@ around 'attrs' => sub {
6767
my $symbol = '&' . $method;
6868
$stash->add_symbol(
6969
$symbol => sub {
70-
my $self = shift;
71-
return $self->dbh->$method(@_);
70+
my $self = shift;
71+
my $wantarray = wantarray;
72+
my $result = eval {
73+
if ($wantarray) {
74+
[$self->dbh->$method(@_)];
75+
}
76+
else {
77+
[scalar $self->dbh->$method(@_)];
78+
}
79+
};
80+
if (not defined $result) {
81+
my $err = $@;
82+
Carp::confess($err);
83+
}
84+
else {
85+
return $wantarray ? @$result : $result->[0];
86+
}
7287
}
7388
);
7489
}
@@ -511,8 +526,8 @@ sub bz_server_version {
511526
sub bz_last_key {
512527
my ($self, $table, $column) = @_;
513528

514-
return $self->last_insert_id(Bugzilla->localconfig->db_name,
515-
undef, $table, $column);
529+
return $self->last_insert_id(Bugzilla->localconfig->db_name, undef, $table,
530+
$column);
516531
}
517532

518533
sub bz_check_regexp {
@@ -579,7 +594,7 @@ sub bz_setup_foreign_keys {
579594
# so if it doesn't have them, then we're setting up FKs
580595
# for the first time, and should be quieter about it.
581596
my $activity_fk = $self->bz_fk_info('profiles_activity', 'userid');
582-
my $any_fks = $activity_fk && $activity_fk->{created};
597+
my $any_fks = $activity_fk && $activity_fk->{created};
583598
if (!$any_fks) {
584599
print get_text('install_fk_setup'), "\n";
585600
}

0 commit comments

Comments
 (0)
Please sign in to comment.