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

Capture Exit Code in MetaCPAN::Script::Runner #1049

Merged
merged 3 commits into from
Feb 22, 2022

Conversation

bodo-hugo-barwich
Copy link
Contributor

@bodo-hugo-barwich bodo-hugo-barwich commented Feb 22, 2022

To satisfy the requirement for MetaCPAN::Script::Runner::run() to return a TRUE value but also keep track of the Exit Code of the Plugin Modules and probable exceptions that happened in the execution the return value was changed:

$ git diff master lib/MetaCPAN/Script/Mapping.pm
diff --git a/lib/MetaCPAN/Script/Mapping.pm b/lib/MetaCPAN/Script/Mapping.pm
index 7e4f47f2..f709aef7 100644
--- a/lib/MetaCPAN/Script/Mapping.pm
+++ b/lib/MetaCPAN/Script/Mapping.pm
@@ -129,7 +129,7 @@ has delete_from_type => (
 );
 
 sub run {
-    my $self   = shift;
+    my $self = shift;
 
     if ( $self->await ) {
         $self->delete_index if $self->arg_delete_index;
@@ -151,9 +151,8 @@ sub run {
         }
     }
 
-    # Correctly reaching this point it will end the application
-    # with the set MetaCPAN::Role::Script::exit_code
-    exit $self->exit_code;
+# The run() method is expected to communicate Success to the superior execution level
+    return ( $self->exit_code == 0 );
 }

But to communicate the exit code to the main application the MetaCPAN::Script::Runner::run() populates a global value MetaCPAN::Script::Runner::EXIT_CODE which then can be read by the main application.

To be able to test all this error capturing a Mock Script module was created and a test that checks different error that could happen.

@bodo-hugo-barwich
Copy link
Contributor Author

bodo-hugo-barwich commented Feb 22, 2022

Running the Test Sequence it produces these results:

$ docker-compose exec -T api_test prove -lr --jobs 2 t
t/00_setup.t ............................... ok
[INFO] Not adding CPAN::Test::Dummy::Perl5::VersionBump::Decrease in M/MI/MIYAGAWA/CPAN-Test-Dummy-Perl5-VersionBump-0.02.tar.gz
[INFO] Existing version 0.02 is greater than 0.01
t/01_darkpan.t ............................. ok
t/script/cover.t ........................... ok
t/server/controller/user/favorite.t ........ ok
t/api/controller/admin.t ................... ok
t/api/controller/search/first.t ............ ok
    # Testing paging with 2 results
t/api/controller/search/web.t .............. ok
t/api/controller/cover.t ................... ok
t/document/author.t ........................ ok
# [fake pod error]
# [fake pod error]
t/document/file.t .......................... ok
t/document/module.t ........................ ok
t/fff_tidyall.t ............................ ok
t/model/archive.t .......................... ok
# Hi Olaf Alders,
# 
# please click on the following link to verify your PAUSE account:
# 
# http://example.com
# 
# Cheers,
# MetaCPAN
t/model/email/pause.t ...................... ok
t/api/queue.t .............................. ok
t/model/release.t .......................... ok
t/model/release/dependencies.t ............. ok
t/model/release/metadata.t ................. ok
t/model/release/reverse_dependencies.t ..... ok
t/model/search.t ........................... ok
t/package.t ................................ ok
t/pod/renderer.t ........................... ok
t/permission.t ............................. ok
t/query/release.t .......................... ok
t/release/badpod.t ......................... ok
t/release/binary-data.t .................... ok
t/release/bugs.t ........................... ok
t/release/common-files.t ................... ok
t/release/devel-gofaster-0.000.t ........... ok
t/release/documentation-hide.t ............. ok
t/release/documentation-not-readme.t ....... ok
t/release/file-changes.t ................... ok
t/release/file-duplicates.t ................ ok
t/release/ipsonar-0.29.t ................... ok
t/release/local-lib.t ...................... ok
t/release/meta-license.t ................... ok
t/release/meta-provides.t .................. ok
t/release/moose.t .......................... ok
t/release/multiple-modules.t ............... ok
t/release/no-modules.t ..................... ok
t/release/no-packages.t .................... ok
t/release/oops-locallib.t .................. ok
t/release/p-1.0.20.t ....................... ok
t/release/packages-unclaimable.t ........... ok
t/release/packages.t ....................... ok
t/release/perl-changes-file.t .............. ok
t/release/pm-PL.t .......................... ok
t/release/pod-examples.t ................... ok
t/release/pod-pm.t ......................... ok
t/release/pod-with-data-token.t ............ ok
t/release/pod-with-generator.t ............. ok
t/release/prefer-meta-json.t ............... ok
t/release/scripts.t ........................ skipped: Scripting is disabled
t/release/some-trial.t ..................... ok
t/release/text-tabs-wrap.t ................. ok
t/release/versions.t ....................... ok
t/release/weblint++-1.15.t ................. ok
t/release/www-tumblr-0.t ................... ok
t/script/load.t ............................ ok
t/script/queue.t ........................... ok
2022/02/22 12:12:48 E mockerror: mock error message
2022/02/22 12:12:48 F mockerror: mock handled error message
t/script/runner.t .......................... ok
    # GET /distribution/System-Command
t/script/river.t ........................... ok
t/server/controller/author.t ............... ok
t/server/controller/bad_request.t .......... ok
t/server/controller/changes.t .............. ok
t/server/controller/contributor.t .......... ok
    # GET /cover/MetaFile-Both-1.1
    # GET /cover/Pod-With-Generator-1
t/server/controller/cover.t ................ ok
t/server/controller/diff.t ................. ok
t/server/controller/distribution.t ......... ok
t/server/controller/download_url.t ......... ok
t/server/controller/file.t ................. ok
t/server/controller/login/pause.t .......... ok
t/server/controller/mirror.t ............... ok
t/server/controller/module.t ............... ok
t/server/controller/package.t .............. ok
t/server/controller/permission.t ........... ok
t/server/controller/pod.t .................. ok
t/server/controller/release.t .............. ok
t/server/controller/root.t ................. ok
t/server/controller/scroll.t ............... ok
t/server/controller/search/autocomplete.t .. ok
t/server/controller/source.t ............... ok
t/server/controller/user/turing.t .......... ok
t/server/not_found.t ....................... ok
t/server/sanitize_query.t .................. skipped: Scripting is disabled
t/types.t .................................. ok
t/util.t ................................... ok
t/test-vars.t .............................. ok
All tests successful.
Files=88, Tests=1256, 322 wallclock secs ( 0.55 usr  0.15 sys + 408.15 cusr 17.53 csys = 426.38 CPU)
Result: PASS

@mickeyn mickeyn merged commit 6eef876 into metacpan:master Feb 22, 2022
@bodo-hugo-barwich
Copy link
Contributor Author

bodo-hugo-barwich commented Feb 22, 2022

@mickeyn thank you. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants