Skip to content

Commit

Permalink
Merge pull request mojolicious#2111 from haarg/fix-app-loading-error-…
Browse files Browse the repository at this point in the history
…reporting

fix error reporting when loading applications with compile errors
  • Loading branch information
mergify[bot] authored Sep 19, 2023
2 parents 4cf8bab + 852a759 commit 2c8d1b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/Mojo/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ sub load_app {
local @ARGS_OVERRIDE = @args;

# Try to load application from script into sandbox
my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]}; do \$path";
my $err = $app ? undef : $@ || $! || "$path did not return a true value";
die qq{Can't load application from file "$path": $err} if $err;
my $app = eval sprintf <<'END_CODE', md5_sum($path);
package Mojo::Server::Sandbox::%s;
do $path or die $@ || $! || "$path did not return a true value";
END_CODE
die qq{Can't load application from file "$path": $@} if $@;
die qq{File "$path" did not return an application object.\n} unless blessed $app && $app->can('handler');
$self->app($app);
};
Expand Down
3 changes: 2 additions & 1 deletion t/mojo/daemon.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ subtest 'Load broken app' => sub {
eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderTest/A.pm") };
like $@, qr/did not return an application object/, 'right error';
eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderException.pm") };
like $@, qr/^Can't load application/, 'right error';
like $@, qr/Missing right curly or square bracket/, 'right error';
like $@, qr/^Can't load application/, 'right error';
};

subtest 'Load app using module_true' => sub {
Expand Down

0 comments on commit 2c8d1b6

Please sign in to comment.