From: des Date: Thu, 14 Jun 2007 16:44:59 +0000 (+0000) Subject: Consistently replace croak with die, and fix a couple of cases where $@ was X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f9e17511cb54933533ec5a363c60e4e1c368c03;p=varnish Consistently replace croak with die, and fix a couple of cases where $@ was incorrectly used in place of $!. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1517 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/regress/lib/Varnish/Test/Case.pm b/varnish-tools/regress/lib/Varnish/Test/Case.pm index 5d352ae4..8414093f 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -31,7 +31,6 @@ package Varnish::Test::Case; use strict; -use Carp 'croak'; use Varnish::Test::Logger; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm index 1c9baee7..ce35c069 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm @@ -33,8 +33,6 @@ package Varnish::Test::Case::Ticket056; use strict; use base 'Varnish::Test::Case'; -use Carp 'croak'; - our $VCL = " sub vcl_recv { pass; @@ -57,13 +55,13 @@ sub testVersionMatch($) { my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - croak 'Client time-out before receiving a (complete) response' - if $event eq 'ev_client_timeout'; - croak 'Server was not contacted by Varnish' - if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; - croak sprintf('Protocol version mismatch: got: %s expected: %s', - $response->protocol, $sv) - if $response->protocol ne $sv; + die 'Client time-out before receiving a (complete) response\n' + if $event eq 'ev_client_timeout'; + die 'Server was not contacted by Varnish\n' + if $self->{'engine'}->{'server'}->{'requests'} != $requests + 1; + die sprintf('Protocol version mismatch: got: %s expected: %s\n', + $response->protocol, $sv) + if $response->protocol ne $sv; return sprintf("Client: %s Server: %s", $cv, $sv); } diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm index bd069efe..df0a30ee 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm @@ -33,8 +33,6 @@ package Varnish::Test::Case::Ticket102; use strict; use base 'Varnish::Test::Case'; -use Carp 'croak'; - our $VCL = <run_loop('ev_client_response', 'ev_client_timeout'); - croak 'Client time-out before receiving a (complete) response' - if $event eq 'ev_client_timeout'; - croak 'Empty body' if $response->content eq ''; - croak 'Incorrect body' if $response->content ne $body; + die 'Client time-out before receiving a (complete) response\n' + if $event eq 'ev_client_timeout'; + die 'Empty body\n' + if $response->content eq ''; + die 'Incorrect body\n' + if $response->content ne $body; } return 'OK'; diff --git a/varnish-tools/regress/lib/Varnish/Test/Client.pm b/varnish-tools/regress/lib/Varnish/Test/Client.pm index 15866e04..8969aefc 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Client.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Client.pm @@ -31,7 +31,6 @@ package Varnish::Test::Client; use strict; -use Carp 'croak'; use IO::Socket::INET; @@ -59,7 +58,7 @@ sub send_request($$;$) { my $fh = IO::Socket::INET->new('Proto' => 'tcp', 'PeerAddr' => 'localhost', 'PeerPort' => '8080') - or croak "socket: $@"; + or die "socket(): $!\n"; $self->{'fh'} = $fh; $self->{'mux'}->add($fh); @@ -120,7 +119,8 @@ sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; if ($$data ne '') { - croak 'Junk or incomplete response' unless $$data =~ "\n\r?\n"; + die 'Junk or incomplete response\n' + unless $$data =~ "\n\r?\n"; my $response = HTTP::Response->parse($$data); $$data = ''; diff --git a/varnish-tools/regress/lib/Varnish/Test/Engine.pm b/varnish-tools/regress/lib/Varnish/Test/Engine.pm index e95b3ac1..995b1211 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Engine.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Engine.pm @@ -31,7 +31,6 @@ package Varnish::Test::Engine; use strict; -use Carp 'croak'; use Varnish::Test::Server; use Varnish::Test::Varnish; @@ -69,10 +68,10 @@ sub log($$$) { sub run_loop($@) { my ($self, @wait_for) = @_; - croak 'Engine::run_loop: Already inside select-loop. Your code is buggy.' + die 'Engine::run_loop: Already inside select-loop. Your code is buggy.\n' if exists($self->{'in_loop'}); - croak 'Engine::run_loop: No events to wait for.' + die 'Engine::run_loop: No events to wait for.\n' if @wait_for == 0; while (@{$self->{'pending'}} > 0) { @@ -107,13 +106,13 @@ sub AUTOLOAD ($;@) { return if $event eq 'DESTROY'; - croak sprintf('Unknown method "%s"', $event) - unless $event =~ /^ev_(.*)$/; + die sprintf('Unknown method "%s"\n', $event) + unless $event =~ /^ev_(.*)$/; $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); @args = $self->{'case'}->$event(@args) - if (defined($self->{'case'}) and $self->{'case'}->can($event)); + if (defined($self->{'case'}) and $self->{'case'}->can($event)); if (@{$self->{'pending'}} > 0) { push(@{$self->{'pending'}}, [ $event, @args ]); diff --git a/varnish-tools/regress/lib/Varnish/Test/Server.pm b/varnish-tools/regress/lib/Varnish/Test/Server.pm index d85a53ff..97a766fd 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Server.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Server.pm @@ -31,7 +31,6 @@ package Varnish::Test::Server; use strict; -use Carp 'croak'; use IO::Socket::INET; @@ -46,7 +45,7 @@ sub new($$) { 'LocalPort' => $port, 'Listen' => 4, 'ReuseAddr' => 1) - or croak "socket: $@"; + or die "socket(): $!\n"; my $self = bless({ 'engine' => $engine, 'mux' => $engine->{'mux'}, @@ -98,7 +97,6 @@ sub got_request($$) { package Varnish::Test::Server::Connection; use strict; -use Carp 'croak'; sub new($$) { my ($this, $server, $fh) = @_; @@ -160,7 +158,8 @@ sub mux_input($$$$) { sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; - croak 'Junk or incomplete request' unless $$data eq ''; + die 'Junk or incomplete request\n' + unless $$data eq ''; } 1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm index f3c5fb89..49e62a48 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm @@ -31,7 +31,6 @@ package Varnish::Test::Varnish; use strict; -use Carp 'croak'; use Socket; @@ -58,7 +57,8 @@ sub new($$;$) { delete $SIG{CHLD}; my $pid = fork; - croak "fork(): $@\n" unless defined($pid); + die "fork(): $!\n" + unless defined($pid); if ($pid == 0) { # Child @@ -126,9 +126,10 @@ sub backend_block($$) { sub send_command($@) { my ($self, @args) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak sprintf('busy awaiting earlier command (%s)', $self->{'pending'}) - if defined $self->{'pending'}; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die sprintf('busy awaiting earlier command (%s)\n', $self->{'pending'}) + if defined $self->{'pending'}; foreach (@args) { if (m/[\s\"\n]/) { @@ -156,16 +157,20 @@ sub use_vcl($$) { sub start_child($) { my ($self) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak 'already started' if $self->{'state'} eq 'started'; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die 'already started\n' + if $self->{'state'} eq 'started'; $self->send_command("start"); } sub stop_child($) { my ($self) = @_; - croak 'not ready' if $self->{'state'} eq 'init'; - croak 'already stopped' if $self->{'state'} eq 'stopped'; + die 'not ready\n' + if $self->{'state'} eq 'init'; + die 'already stopped\n' + if $self->{'state'} eq 'stopped'; $self->send_command("stop"); } @@ -180,7 +185,8 @@ sub kill($;$) { my ($self, $signal) = @_; $signal ||= 15; - croak 'Not running' unless defined($self->{'pid'}); + die 'Not running\n' + unless defined($self->{'pid'}); kill($signal, $self->{'pid'}); delete $self->{'pid'}; }