May 2011 Archives

MooseX::Types::Structured - how I detest thee!

Yeah, thanks, “something failed validation”. You’re the damn computer, how about you tell me which field you didn’t like?!

Error: Attribute (payload) does not pass the type constraint because:
Validation failed for '
    ArrayRef[
    MooseX::Types::Structured::Dict[
        some_id,
        Int,
        another_id,
        MooseX::Types::Structured::Optional[Int],
        some_code,
        MooseX::Types::Structured::Optional[Str],
        some_colour,
        MooseX::Types::Structured::Optional[Str],
        some_source,
        MooseX::Types::Structured::Optional[__ANON__],
        different_code,
        MooseX::Types::Structured::Optional[Int],
        restriction,
        MooseX::Types::Structured::Optional[
        MooseX::Types::Structured::Dict[
            add,
            MooseX::Types::Structured::Optional[ArrayRef[Str]],
            remove,
            MooseX::Types::Structured::Optional[ArrayRef[Str]]
        ]
        ],
        a_term,
        MooseX::Types::Structured::Optional[Str],
        yet_another_id,
        MooseX::Types::Structured::Optional[Str],

  # snip many more fields #
  # snip many more fields #

' failed with value ARRAY(0x1d263760)

You really aren’t being very helpful!

EDIT: Sample code and output

I put together this quick script:

#!/usr/bin/env perl

package Thingy;
use Moose;
use MooseX::Types::Moose qw(Str Int HashRef ArrayRef);
use MooseX::Types::Structured qw(Dict Tuple Optional);

has payload => (
    is => 'rw',
    isa=>ArrayRef[
        MooseX::Types::Structured::Dict[
            some_id => Int,
            another_id => Int,
            some_colour => Str,
            yet_another_id => MooseX::Types::Structured::Optional[Int],
        ]
    ],
);

package main;
use TryCatch;
use Data::Dump qw(pp);

my $thingy = Thingy->new;

try {
    $thingy->payload([
        { some_id => 'Ten' },
    ]);
}
catch($err) {
    warn $err;
}

warn "Moose: $Moose::VERSION";
warn "MooseX::Types::Structured: $MooseX::Types::Structured::VERSION";

I ran the script on two different servers, with different Moose-y versions:

$ perl structured.pl
Attribute (payload) does not pass the type constraint because: Validation failed for 'ArrayRef[MooseX::Types::Structured::Dict[some_id,Int,another_id,Int,some_colour,Str,yet_another_id,MooseX::Types::Structured::Optional[Int]]]' failed with value ARRAY(0x1be8f990) at structured.pl line 27
eval {...} called at structured.pl line 31
Moose: 0.93 at structured.pl line 35.
MooseX::Types::Structured: 0.21 at structured.pl line 36.

Newer versions:

$ perl structured.pl
Attribute (payload) does not pass the type constraint because: Validation failed for 'ArrayRef[MooseX::Types::Structured::Dict[some_id,Int,another_id,Int,some_colour,Str,yet_another_id,MooseX::Types::Structured::Optional[Int]]]' with value ARRAY(0x89c4688) at structured.pl line 27
eval {...} called at structured.pl line 26
Moose: 1.21 at structured.pl line 35.
MooseX::Types::Structured: 0.26 at structured.pl line 36.

I then made sure I had the latest version of ::Structured, and re-ran the script:

$ perl structured.pl
Attribute (payload) does not pass the type constraint because: Validation failed for 'ArrayRef[MooseX::Types::Structured::Dict[some_id,Int,another_id,Int,some_colour,Str,yet_another_id,MooseX::Types::Structured::Optional[Int]]]' with value ARRAY(0xc07b350) at structured.pl line 27
eval {...} called at structured.pl line 26
Moose: 1.21 at structured.pl line 35.
MooseX::Types::Structured: 0.27 at structured.pl line 36.

About Chisel

user-pic