Skip Menu |

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

Report information
The Basics
Id: 71069
Status: open
Priority: 0/
Queue: MooseX-Types-Structured

People
Owner: Nobody in particular
Requestors: tn [...] movb.de
Cc:
AdminCc:

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



Subject: Constraint error message ignored
Date: Mon, 19 Sep 2011 16:18:12 +0200
To: bug-MooseX-Types-Structured [...] rt.cpan.org
From: Tobias Nissen <tn [...] movb.de>
Hi, MooseX-Types-Structured doesn't seem to care for constraint error messages provided in a subtype declaration: { package Foo; use Moose; use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw(Str); use MooseX::Types::Structured qw(Dict); use MooseX::Types -declare => [qw(IPv4Address)]; subtype IPv4Address, as Str, where { /^\s*(\d{1,3}\.){3}\d{1,3}\s*$/ }, message { "Not an IPv4 address: '$_'" }; has 'foo' => ( is => 'rw', isa => Dict[ address => IPv4Address ], ); sub BUILD { my $self = shift; $self->foo({address => '0.0.BAD.0'}); } 1; } my $foo = Foo->new(); This results in Attribute (foo) does not pass the type constraint because: Validation failed for 'MooseX::Types::Structured::Dict[address,Foo::IPv4Address]' with value { address: "0.0.BAD.0" } at accessor Foo::foo (defined at ex.pl line 16) line 4 Foo::foo('Foo=HASH(0x2a0e450)', 'HASH(0x2ce1290)') called at ex.pl line 24 Foo::BUILD('Foo=HASH(0x2a0e450)', 'HASH(0x1dbdd80)') called at /usr/lib/perl5/Class/MOP/Method.pm line 125 [and so on...] I would have expected to get the provided message "Not an IPv4 address..." This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux-gnu-thread-multi on a recently updated Debian Wheezy. Cheers, Tobias
Download signature.asc
application/pgp-signature 198b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #71069] Constraint error message ignored
Date: Mon, 19 Sep 2011 07:41:10 -0700 (PDT)
To: "bug-MooseX-Types-Structured [...] rt.cpan.org" <bug-MooseX-Types-Structured [...] rt.cpan.org>
From: John Napiorkowski <jjn1056 [...] yahoo.com>
Show quoted text
>________________________________ >From: Tobias Nissen via RT <bug-MooseX-Types-Structured@rt.cpan.org> >To: >Sent: Monday, September 19, 2011 10:18 AM >Subject: [rt.cpan.org #71069] Constraint error message ignored > >Mon Sep 19 10:18:54 2011: Request 71069 was acted upon. >Transaction: Ticket created by tn@movb.de >       Queue: MooseX-Types-Structured >     Subject: Constraint error message ignored >   Broken in: (no value) >    Severity: (no value) >       Owner: Nobody >  Requestors: tn@movb.de >      Status: new >Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=71069 > > > >Hi, > >MooseX-Types-Structured doesn't seem to care for constraint error >messages provided in a subtype declaration: > >  { >  package Foo; > >  use Moose; >  use Moose::Util::TypeConstraints; >  use MooseX::Types::Moose qw(Str); >  use MooseX::Types::Structured qw(Dict); >  use MooseX::Types -declare => [qw(IPv4Address)]; > >  subtype IPv4Address, >      as Str, >      where { /^\s*(\d{1,3}\.){3}\d{1,3}\s*$/ }, >      message { "Not an IPv4 address: '$_'" }; > >  has 'foo' => ( >      is  => 'rw', >      isa => Dict[ address => IPv4Address ], >  ); > >  sub BUILD { >      my $self = shift; > >      $self->foo({address => '0.0.BAD.0'}); >  } > >  1; >  } > >  my $foo = Foo->new(); > >This results in > >  Attribute (foo) does not pass the type constraint because: Validation failed for 'MooseX::Types::Structured::Dict[address,Foo::IPv4Address]' with value { address: "0.0.BAD.0" } at accessor Foo::foo (defined at ex.pl line 16) line 4 >    Foo::foo('Foo=HASH(0x2a0e450)', 'HASH(0x2ce1290)') called at ex.pl line 24 >    Foo::BUILD('Foo=HASH(0x2a0e450)', 'HASH(0x1dbdd80)') called at /usr/lib/perl5/Class/MOP/Method.pm line 125 >        [and so on...] > >I would have expected to get the provided message "Not an IPv4 address..." > >
MXTS doen't have the most awesome error messages, but this is clearly just busted.  Is there any change you could check in a failing test, that would help me get to it quicker.  The repo is not currently on github, let me know if mirroring there would help you. thanks! john Show quoted text
> > >This is perl 5, version 12, subversion 4 (v5.12.4) built for >x86_64-linux-gnu-thread-multi on a recently updated Debian Wheezy. > >Cheers, >Tobias > > > >
Subject: Re: [rt.cpan.org #71069] Constraint error message ignored
Date: Thu, 22 Sep 2011 15:04:20 +0200
To: bug-MooseX-Types-Structured [...] rt.cpan.org
From: Tobias Nissen <tn [...] movb.de>
jjn1056@yahoo.com via RT wrote: Show quoted text
> Tobias Nissen wrote:
> >MooseX-Types-Structured doesn't seem to care for constraint error > >messages provided in a subtype declaration: > > > >  { > >  package Foo; > > > >  use Moose; > >  use Moose::Util::TypeConstraints; > >  use MooseX::Types::Moose qw(Str); > >  use MooseX::Types::Structured qw(Dict); > >  use MooseX::Types -declare => [qw(IPv4Address)]; > > > >  subtype IPv4Address, > >      as Str, > >      where { /^\s*(\d{1,3}\.){3}\d{1,3}\s*$/ }, > >      message { "Not an IPv4 address: '$_'" }; > > > >  has 'foo' => ( > >      is  => 'rw', > >      isa => Dict[ address => IPv4Address ], > >  ); > > > >  sub BUILD { > >      my $self = shift; > > > >      $self->foo({address => '0.0.BAD.0'}); > >  } > > > >  1; > >  } > > > >  my $foo = Foo->new(); > > > >This results in > > > >  Attribute (foo) does not pass the type constraint because: > >Validation failed for > >'MooseX::Types::Structured::Dict[address,Foo::IPv4Address]' with > >value { address: "0.0.BAD.0" } at accessor Foo::foo (defined at > >ex.pl line 16) line 4 Foo::foo('Foo=HASH(0x2a0e450)', > >'HASH(0x2ce1290)') called at ex.pl line 24 > >Foo::BUILD('Foo=HASH(0x2a0e450)', 'HASH(0x1dbdd80)') called > >at /usr/lib/perl5/Class/MOP/Method.pm line 125 [and so on...] > > > >I would have expected to get the provided message "Not an IPv4 > >address..."
> > MXTS doen't have the most awesome error messages, but this is clearly > just busted. [...]
OK, I looked a bit more into it. If I had declared foo like this subtype StructuredType, as Dict[ address => IPv4Address ], message { "Nice validation error message" }; has 'foo' => ( is => 'rw', isa => StructuredType, ); I would get "Nice validation error message". That's a little bit better than the other behaviour. However, now I'm not sure if the behaviour I had expected when I made the bug report, would be a good design choice. If the validation would give "Not an IPv4 address..." when there's no message declared for the structured type, that would be reasonable. But what if there was a message declared, as in the example above? If the error occurs when validating the simple type in the structured type, one might argue that the top level error message (the one of the structured type) should be displayed. Others might argue the other way around. I think in this situation it'd be sensible to display the full validation error stack, beginning at the bottom (where the error first occured). What do you think?
Download signature.asc
application/pgp-signature 198b

Message body not shown because it is not plain text.