Skip Menu |
 

This queue is for tickets about the MooseX-Getopt CPAN distribution.

Report information
The Basics
Id: 83307
Status: open
Priority: 0/
Queue: MooseX-Getopt

People
Owner: rjbs [...] cpan.org
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.55
Fixed in: (no value)



Subject: usage not customizable for errors

 The current implementation details seem to provide an interesting qurik:

if you run a command, and the command lacks a required attribute, the "help/usage" error is displayed. 

However, unlike "command --help", there is no way to change the displayed error in anyway, as the defined way of tweaking the error is never called.

In the attached example,  'example.pl' bails with a general GLD error, and 'example.pl -h'  *also* fail with a general GLD error. ( -a is required, even to display help! )

The only way to trigger the modified usage is 'example.pl -a foo -h'

Incidentally, I've even tried wrapping the private method '_getopt_get_options', ( where the stack trace showed the error was triggered ), but that also proved useless, as the actual point of failure is within Getopt::Long space, 

https://metacpan.org/source/ETHER/MooseX-Getopt-0.55/lib/MooseX/Getopt/GLD.pm#L52

 

And upon discovering that, I somewhat got lost and decided to file a bug so somebody who knows what they're doing could sort it out =)
 

usage: example.pl [-?ah] [long options...]

-h -? --usage --help  Prints this usage information.

-a --attribute        

 at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Getopt/Long/Descriptive/Usage.pm line 101.

Getopt::Long::Descriptive::Usage::die('Getopt::Long::Descriptive::Usage=HASH(0x225e0e8)', 'HASH(0x23a36a8)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Getopt/Long/Descriptive.pm line 281

Getopt::Long::Descriptive::_validate_with('name', 'attribute', 'params', 'HASH(0x23a02f8)', 'spec', 'HASH(0x23971f8)', 'opts', 'ARRAY(0x23a2d30)', 'usage', ...) called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Getopt/Long/Descriptive.pm line 194

Getopt::Long::Descriptive::__ANON__('usage: %c %o', 'ARRAY(0x23933b0)', 'ARRAY(0x2397ac8)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Getopt/Long/Descriptive.pm line 81

Getopt::Long::Descriptive::describe_options('usage: %c %o', 'ARRAY(0x23933b0)', 'ARRAY(0x2397ac8)', 'HASH(0x2397ee8)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/GLD.pm line 52

Class::MOP::Class:::around('CODE(0x232d930)', 'Example', 'HASH(0x2301e78)', 'ARRAY(0x224e330)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/x86_64-linux/Class/MOP/Method/Wrapped.pm line 162

Class::MOP::Method::Wrapped::__ANON__('Example', 'HASH(0x2301e78)', 'ARRAY(0x224e330)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/x86_64-linux/Class/MOP/Method/Wrapped.pm line 91

Example::_getopt_get_options('Example', 'HASH(0x2301e78)', 'ARRAY(0x224e330)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 132

MooseX::Getopt::Basic::__ANON__() called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Try/Tiny.pm line 71

eval {...} called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Try/Tiny.pm line 67

Try::Tiny::try('CODE(0x239f830)', 'Try::Tiny::Catch=REF(0x239fda0)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 136

MooseX::Getopt::Basic::_parse_argv('Example', 'options', 'ARRAY(0x2363f30)', 'params', 'HASH(0x2392d38)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 79

MooseX::Getopt::Basic::process_argv('Example') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 105

MooseX::Getopt::Basic::new_with_options('Example') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 168.

MooseX::Getopt::Basic::_getopt_spec_exception('Example', 'ARRAY(0x231d340)', 'Mandatory parameter \'attribute\' missing in call to (eval)\x{a}\x{a}...') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 135

MooseX::Getopt::Basic::__ANON__('Mandatory parameter \'attribute\' missing in call to (eval)\x{a}\x{a}...') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/Try/Tiny.pm line 100

Try::Tiny::try('CODE(0x239f830)', 'Try::Tiny::Catch=REF(0x239fda0)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 136

MooseX::Getopt::Basic::_parse_argv('Example', 'options', 'ARRAY(0x2363f30)', 'params', 'HASH(0x2392d38)') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 79

MooseX::Getopt::Basic::process_argv('Example') called at /home/kent/perl5/perlbrew/perls/perl-blead/lib/site_perl/5.17.9/MooseX/Getopt/Basic.pm line 105

MooseX::Getopt::Basic::new_with_options('Example') called at example.pl line 29

Subject: example.pl
Download example.pl
text/x-perl 645b
#!/usr/bin/env perl use strict; use warnings; use utf8; { package Example; use Moose; with 'MooseX::Getopt'; has attribute => ( is => rw =>, required => 1, traits => ['Getopt'], cmd_aliases => a =>, ); around print_usage_text => sub { my ( $orig, $self, @args ) = @_; # This is useless because the core method invoked does exit 0 at the end. # $self->$orig(@args); print $args[0]->text; print "\n additional usage text via print_usage_text \n"; exit 0; }; __PACKAGE__->meta->make_immutable; } Example->new_with_options->run;
Download (untitled) / with headers
text/plain 668b
On Wed Feb 13 11:50:54 2013, KENTNL wrote: Show quoted text
> The current implementation details seem to provide an interesting > qurik: > > if you run a command, and the command lacks a required attribute, the > "help/usage" error is displayed.
Confirmed. What's happening is GLD itself is performing the validation checks, and returning the (standard) usage text right in its exception, which MXGO happily die()s with, without ever passing through print_usage_text(). There ought to be an option to pass to GLD to return a more abbreviated error when validation fails, so we can print the usage text ourselves along with a nice form of the error (i.e. not including "at eval..").
Download (untitled) / with headers
text/plain 674b
On Sat Feb 16 09:11:26 2013, ETHER wrote: Show quoted text
> There ought to be an option to pass to GLD to return a more abbreviated > error when validation fails, so we can print the usage text ourselves > along with a nice form of the error (i.e. not including "at eval..").
This might get pretty hairy. $usage->die is called right in GLD, and there isn't an easy way to stop that. However, if we could modify that usage object, we could get it to return a more abbreviated error message and then capture that and emit our own with print_usage_text. Or, possibly, pass our print_usage_text sub into GLD so it can call it itself at the right time? Punting over to rjbs for comments...


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.