Improved error handling for the case where the database configuration doesn't exist and therefore every output attempt raises database errors. Fatal database errors are now fatal, missing database configurations is not. This would be a lot cleaner if Perl exceptions were objects... Also improved some of the error messages.

This commit is contained in:
ian%hixie.ch 2001-11-08 16:10:21 +00:00
parent 2888df9f80
commit a15a7b4506
3 changed files with 20 additions and 12 deletions

View File

@ -51,7 +51,7 @@ sub database {
}
}
}
$self->error(1, 'Configuration Error: There is no suitable \''.$self->databaseName.'\' database installed.');
$self->error(1, 'There is no suitable \''.$self->databaseName.'\' database installed.');
}
sub helper {

View File

@ -139,7 +139,7 @@ sub variants {
if ($@) {
# ok, so, er, it seems that didn't go to well
# XXX do we want to do an error here or something?
$self->warn(4, "Just so you know, I'm going to silently ignore the fact that I completely failed to get any variants... For what it's worth, the error was: $@");
$self->warn(4, "While I was looking for the variants, I failed with: $@");
return []; # no variants here, no sir!
}
}

View File

@ -52,20 +52,28 @@ sub init {
my($app) = @_;
eval {
$self->getConfig($app);
my $type = $self->type;
my $name = $self->name;
my $host = $self->host;
my $port = $self->port;
$self->handle(DBI->connect("DBI:$type:$name:$host:$port",
$self->username, $self->password,
{RaiseError => 0, PrintError => 0, AutoCommit => 1, Taint => 1}));
$self->errstr($DBI::errstr);
$self->dump(9, 'created a database object without raising an exception');
};
if ($@) {
$self->handle(undef);
$self->errstr($@);
$self->dump(9, "failed to connect to the database because of $@");
$self->dump(9, "failed to get the database configuration, not going to bother to connect: $@");
} else {
eval {
my $type = $self->type;
my $name = $self->name;
my $host = $self->host;
my $port = $self->port;
$self->handle(DBI->connect("DBI:$type:$name:$host:$port",
$self->username, $self->password,
{RaiseError => 0, PrintError => 0, AutoCommit => 1, Taint => 1}));
$self->errstr($DBI::errstr);
$self->dump(9, 'created a database object without raising an exception');
};
if ($@) {
$self->handle(undef);
$self->errstr($@);
$self->error(1, "failed to connect to the database because of $@");
}
}
}