Skip to content

Commit

Permalink
more consistent error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 3, 2014
1 parent b8e10a0 commit 2b85923
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/connect-proxy.pl
Expand Up @@ -76,7 +76,7 @@
}
);
}
) or die "Couldn't create listen socket!\n";
);

print <<'EOF';
Starting CONNECT proxy on port 3000.
Expand Down
2 changes: 1 addition & 1 deletion examples/microhttpd.pl
Expand Up @@ -32,7 +32,7 @@
);
$stream->on(close => sub { delete $buffer{$id} });
}
) or die "Couldn't create listen socket!\n";
);

print <<'EOF';
Starting server on port 8080.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Client.pm
Expand Up @@ -60,7 +60,7 @@ sub _connect {
$options{LocalAddr} = $args->{local_address} if $args->{local_address};
$options{PeerAddr} =~ s/[\[\]]//g if $options{PeerAddr};
my $class = IPV6 ? 'IO::Socket::IP' : 'IO::Socket::INET';
return $self->emit(error => "Couldn't connect: $@")
return $self->emit(error => "Can't connect: $@")
unless $self->{handle} = $handle = $class->new(%options);
}
$handle->blocking(0);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -15,7 +15,7 @@ sub build_app {
my ($self, $app) = @_;
local $ENV{MOJO_EXE};
return $app->new unless my $e = Mojo::Loader->new->load($app);
die ref $e ? $e : qq{Couldn't find application class "$app" in \@INC.\n};
die ref $e ? $e : qq{Can't find application class "$app" in \@INC. (@INC)\n};
}

sub build_tx {
Expand Down Expand Up @@ -52,7 +52,7 @@ sub load_app {
# Try to load application from script into sandbox
my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]};"
. 'return do($path) || die($@ || $!);';
die qq{Couldn't load application from file "$path": $@} if !$app && $@;
die qq{Can't load application from file "$path": $@} if !$app && $@;
die qq{File "$path" did not return an application object.\n}
unless blessed $app && $app->isa('Mojo');
$self->app($app);
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -17,7 +17,7 @@ sub parse {
my $config
= eval 'package Mojolicious::Plugin::Config::Sandbox; no warnings;'
. "sub app; local *app = sub { \$app }; use Mojo::Base -strict; $content";
die qq{Couldn't load configuration from file "$file": $@} if !$config && $@;
die qq{Can't load configuration from file "$file": $@} if !$config && $@;
die qq{Configuration file "$file" did not return a hash reference.\n}
unless ref $config eq 'HASH';

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/JSONConfig.pm
Expand Up @@ -11,7 +11,7 @@ sub parse {
my $json = Mojo::JSON->new;
my $config = $json->decode($self->render($content, $file, $conf, $app));
my $err = $json->error;
die qq{Couldn't parse config "$file": $err} if !$config && $err;
die qq{Can't parse config "$file": $err} if !$config && $err;
die qq{Invalid config "$file"} if !$config || ref $config ne 'HASH';

return $config;
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/daemon.t
Expand Up @@ -67,11 +67,11 @@ eval {
Mojo::Server::Daemon->new->load_app(
"$FindBin::Bin/lib/Mojo/LoaderException.pm");
};
like $@, qr/^Couldn't load application/, 'right error';
like $@, qr/^Can't load application/, 'right error';

# Load missing application class
eval { Mojo::Server::Daemon->new->build_app('Mojo::DoesNotExist') };
is $@, qq{Couldn't find application class "Mojo::DoesNotExist" in \@INC.\n},
like $@, qr/^Can't find application class "Mojo::DoesNotExist" in \@INC/,
'right error';

# Transaction
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/user_agent_online.t
Expand Up @@ -87,7 +87,7 @@ ok $tx->error, 'has error';
$tx = $ua->build_tx(GET => 'http://cdeabcdeffoobarnonexisting.com');
$ua->start($tx);
ok $tx->is_finished, 'transaction is finished';
like $tx->error->{message}, qr/^Couldn't connect/, 'right error';
like $tx->error->{message}, qr/^Can't connect/, 'right error';

# Fresh user agent again
$ua = Mojo::UserAgent->new;
Expand Down

0 comments on commit 2b85923

Please sign in to comment.