Skip to content

Commit 075185e

Browse files
committed
Rewrite Error message Address in use #485
"Can't create listen socket: Address already in use" is rewriten as "Can't create listen socket for (http://*:3000): Address already in use" it changes all "Can't create listen socket:" messages to "Can't create listen socket for ($listen_URL):" It has a test in t/command/daemon.t that test the new messge when no port is specified Signed-off-by: Jose Luis Perez Diez <jluis@escomposlinux.org>
1 parent cadad73 commit 075185e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/Statocles/Command.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ sub main {
170170
}
171171

172172
# Using start() instead of run() so we can stop() inside the tests
173-
$daemon->start;
173+
eval {$daemon->start};
174+
if ($@) {
175+
my $port = $opt{port} ||$ENV{MOJO_LISTEN} || 3000;
176+
$@ =~ s/socket:/socket on port $port:/;
177+
die $@;
178+
}
174179

175180
# Find the port we're listening on
176181
my $id = $daemon->acceptors->[0];

t/command/daemon.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ subtest 'listen on a specific port' => sub {
117117
'contains http port information';
118118
};
119119

120+
subtest 'Try to launch 2 daemons' => sub {
121+
122+
local $ENV{MOJO_LOG_LEVEL} = 'info'; # But sometimes this isn't set?
123+
my @args = (
124+
'--config' => "$config_fn",
125+
'daemon',
126+
'-v', # watch lines are now behind -v
127+
);
128+
if (my $pid = fork) {
129+
sleep 1;
130+
eval { Statocles::Command->main( @args ) };
131+
kill 9, $pid;
132+
} else {
133+
#my ( $out2, $err2, $exit2 ) =
134+
capture { Statocles::Command->main( @args ) };
135+
}
136+
my $err = $@ =~ m|\(http://\*:(\d*)\):|;
137+
my $port = $1;
138+
is $port, 3000, 'correct port';
139+
ok $err, "there was anoter proccess listening at $port";
140+
like $@, qr{^Can't create listen socket for \(http://\*:$port\):},
141+
'contains http port information';
142+
};
143+
144+
120145
subtest '--date' => sub {
121146
my ( $tmp, $config_fn, $config ) = build_temp_site( $SHARE_DIR );
122147

0 commit comments

Comments
 (0)