Moose Loose Ends Part the First

Its error day here in the Moose Pen

Well not really error day more like lets have a look at the errors I spit out and attempt to standardize them, but that is too long for a catch title.

First thing to do was have a look at how my Accessor.pm and from a review I see that I only use 'die'. I found it in about 22 spots in the code. The good thing is I don;t have a mixture of croak, die and croak
carp and confess. The bad thing is I wad never very consistent with my die messages;

Most are just simple strings such as


Attempt to use create with no_create flag on!
The \$container Hash-Ref cannot be empty

Some are a little more informative;

Database::Accessor::->update:
Element {name=>"salary",
view=>"people"}
not in the elements array!
Only elements from that array can be added!!"

and some are rather cryptic;

Unable to open $path: $!"

Now these are just the ones that I have entered into the main code and have 100% control over. There are also errors that come direly from Moose like a fail on a required attribute

Attribute (elements) is required at C:/Dwimperl/perl/site/lib/Class/MOP/Method/Wrapped.pm line 164# Looks like your test exited with 255 before it could output anything.

or

Attribute (name) is required at D:\GitHub\database-accessor\lib/Database/Accessor/Types.pm

Again not giving the end user much information. As I could be spending quite some time back tracing what 'elements' is that error referring to? The Database::Accessor instance 'elements' array or perhaps one the 'elements' on my 'gather' attribute.

That required 'name' is even harder to debug as it could be missing from any attribute that has or is an 'Element' class.

Now this is compounded even further when we get into types and coercion as you can see an error like this


Attribute (left) does not pass the type constraint because: Validation failed for 'ArrayRefofElements|ArrayRefofExpressions|ArrayRefofParams|Element|Expression|Function|If|Param' with value

At least when I get a fail on some of the predefined types it give me a good hint;


Attribute (type) does not pass the type constraint because: The Link 'SUPPER', is not a valid Accessor Link! Try one of 'LEFT', 'OUTER', 'RIGHT'
where the error might be.

I am 100% sure I have eliminated all 'Moose POOP' errors. These are the massively long and cryptic ones a developer sees when they make some sort of Moose error like forgetting to add in a 'requires' sub in a consuming class or a role. So no


Moose::Exception::_build_trace('Moose::Exception::RequiredMethodsNotImplementedByClass=HASH(0x4e587f8)') called at reader Moose::Exception::trace defined at /wwwveh/local/lib/perl5/x86_64-linux-thread-multi/Moose/Exception.pm line 9) line 8
Moose::Exception::trace('Moose::Exception::RequiredMethodsNotImplementedByClass=HASH(0x4e587f8)') called at /wwwveh/local/lib/perl5/x86_64-linux-thread-multi/Moose/Exception.pm line 49 Moose::Exception::BUILD('Moose::Exception::RequiredMethodsNotImplementedByClass=HASH(0x4e587f8)', 'HASH(0x4e587c8)') called at /wwwveh/local/lib/perl5/x86_64-linux-thread-multi/Class/MOP/Method.pm line 126 Class::MOP::Method::execute('Moose::Meta::Method=HASH(0x4e93000)',Moose::Exception::RequiredMethodsNotImplemente dByClass=HASH(0x4e587f8)',
'HASH(0x4e587c8)') called at /wwwveh/local/lib/perl5/x86_64-linux-thread-multi/Moos/Object.pm line 55
...

I guess my homework for tonight is to see if I can find a way to handle all the errors though one sub so I can at least point to where the error is and fill in a little more detail. It would be great if I could return something like this;


Database::Accessor->Elements:: Error 'name' required at '*-->';
{
view => { name => 'people' },
elements => [ { '*-->nam' => 'first_name', }*,
{ name => 'last_name', }, ],
};

But It think I am hoping for a little too much?

poopymoose.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations