Skip to content

Commit 2c8d1b6

Browse files
authored
Merge pull request #2111 from haarg/fix-app-loading-error-reporting
fix error reporting when loading applications with compile errors
2 parents 4cf8bab + 852a759 commit 2c8d1b6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/Mojo/Server.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ sub load_app {
5454
local @ARGS_OVERRIDE = @args;
5555

5656
# Try to load application from script into sandbox
57-
my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]}; do \$path";
58-
my $err = $app ? undef : $@ || $! || "$path did not return a true value";
59-
die qq{Can't load application from file "$path": $err} if $err;
57+
my $app = eval sprintf <<'END_CODE', md5_sum($path);
58+
package Mojo::Server::Sandbox::%s;
59+
do $path or die $@ || $! || "$path did not return a true value";
60+
END_CODE
61+
die qq{Can't load application from file "$path": $@} if $@;
6062
die qq{File "$path" did not return an application object.\n} unless blessed $app && $app->can('handler');
6163
$self->app($app);
6264
};

t/mojo/daemon.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ subtest 'Load broken app' => sub {
8888
eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderTest/A.pm") };
8989
like $@, qr/did not return an application object/, 'right error';
9090
eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderException.pm") };
91-
like $@, qr/^Can't load application/, 'right error';
91+
like $@, qr/Missing right curly or square bracket/, 'right error';
92+
like $@, qr/^Can't load application/, 'right error';
9293
};
9394

9495
subtest 'Load app using module_true' => sub {

0 commit comments

Comments
 (0)