jadeallenx / net-amazon-ec2

Perl interface to the Amazon Elastic Compute Cloud (EC2) environment.

Home Page:http://metacpan.org/release/Net-Amazon-EC2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Throw exception instead of return an error

miquelruiz opened this issue · comments

Hi,

I think it would be better to throw an exception instead of returning an error when a method call fails.

I'm thinking in a patch where you could activate the new behaviour via a new constructor parameter (ala DBI's "RaiseError"). It would be off by default, so it won't break backwards compatibility.

Would you be interested in it? Maybe there's a reason which suggests this is not a good idea?

Best regards,
Miquel

I admit I don't much like the current error behavior. What kind of exception did you have in mind? Carp::confess?

There are some possibilities here. My ideas are:

  • Throw the exception from within the function "_parse_errors", making it throw the "Net::Amazon::EC2::Errors" object instead of returning it if the new behaviour is enabled.
  • use "die" to throw the exception if the response code is a 5XX (Amazon or networking fault)
  • use "confess" or "croak" (could also be configured via construction parameter) if the response code is a 4XX (and thus, an incorrect call from the user)

What do you think?

Regards,
Miquel

I would prefer to use croak instead of die and confess when a stacktrace would be helpful - I'm not sure exactly when that might come up but I think this is a good idea. My further preference would be to make this behavior the default and allow the previous behavior of a flag is set like "ReturnErrors" or something along those lines.

This sounds like a great idea. Looking forward to seeing what you come up with.

Thanks!!

P.S. Please add to the tests to handle your new behaviors.

By mistake I sent the pull request as a new issue (#9). We can close this one and track it from there.

Regards,
Miquel

Cool