Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error reporting when loading applications with compile errors #2111

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading