Perl DBIx::Error
模块可以在Perl HandleError
的{{1}}中使用。
我想知道是否有传递一些参数的选项
DBIx::Error
到底层
Devel::StackTrace
。那是因为我们真的使用了一些
长字符串作为函数调用中的参数。如果我现在打电话给
DBI
方法,我们的日志正在爆炸。
DBIx::Error->stack_trace
知道参数Devel::Stacktrace
和no_args
这是完美的我们的需求。但他们是如何深入研究的
StackTrace包?
该模块的实际维护者的电子邮件 - abraxxa@cpan.org-似乎已被破坏。
有没有人提供有用的提示?
答案 0 :(得分:0)
这就是我的意思:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBIx::Error;
use TryCatch;
try {
my $dbh = connectDatabase();
doSomeThingWithDatabase($dbh, "i am a really long parameter and will not be shown complete in any logs");
} catch (DBIx::Error $e) {
print "database error: " . $e->message . "\n"
. "Trace: " . $e->stack_trace
. "\n";
}
sub connectDatabase {
my $dbh = DBI->connect($dsn, $user, $pass);
$dbh->{ShowErrorStatement} = 1;
# V1: works, but shows the full parameter
#$dbh->{HandleError} = DBIx::Error->HandleError;
# V2: works, but the stack_trace_args parameter gets ignored
$dbh->{HandleError} = DBIx::Error->HandleError(stack_trace_args => [no_args => 1]);
# V3: Any suggestions ????
return $dbh;
}
sub doSomeThingWithDatabase {
my ($dbh, $reallyLongParameter) = @_;
$dbh->do("selec foo from bar");
}