This is an initial PR for Issue #70 and handling of frame errors in general.#80
This is an initial PR for Issue #70 and handling of frame errors in general.#80Donatello-za wants to merge 3 commits into
Conversation
- Generator will generate exception classes and error fetcher from amqp spec. Todo: - Support AbstractFrame also, currently only MethodFrame frames are supported. - Implement usage of the new error fetching class everywhere.
… exceptions. - This commit is only for discussion on the PR and is not final.
|
Hello! First thank you for your work. I agree that when client receives an error from the broker (either soft /channel/ error, or hard /connection/ error), it should present the user an appropriate error message. However, generating separate classes for all error types seems a little superfluous to me - most of these exceptions won't be ever thrown as they're not used by the broker (e.g. https://github.com/rabbitmq/rabbitmq-server/search?q=protocol_error&type=Code). I think using class Also please note I intend to do some backward-incompatible changes for new version of the library => #79 - I've added reference to this PR to the issue. |
This PR consists of the following and I'd like us to discuss it so that it can perhaps be fully implemented if everyone is happy with the way it works:
FrameExceptionextendsBunnyExceptionFrameSoftErrorExceptionextendsFrameExceptionFrameHardErrorExceptionextendsFrameExceptionThe generator will generate all the soft error and hard error frame exceptions source code in the format:
FrameHardError???ExceptionandFrameSoftError???Exception, these extend eitherFrameHardErrorExceptionorFrameSoftErrorExceptiondepending on the error type. Examples are:FrameHardError320ExceptionandFrameSoftError404ExceptionThe generator also generates a new class called
FrameErrorunderBunny/Protocol. This class can determine and return the appropriate exception for any given frame. For example, inChannel.phpon line 624 you have the following statement:This can be replaced with something like:
Which will throw the following exception if one attempts to publish a message to an exchange called
whoopswhich doesn't exist:Bunny\Exception\FrameSoftError404Exception: Channel method frame error received.: AMQP Error: "404 NOT_FOUND - no exchange 'whoops' in vhost '/'" in class Bunny\Protocol\MethodChannelCloseFrame (channel:close).As you can see the error is quite detailed. The
FrameErrorclass will automatically drop to a lower detailed error message depending on the type of frame and the information it has available (i.e. replyCode, replyText, classId, methodId, etc.)If the frame does not have replyCode and replyText properties a FrameException will be returned instead of one of the hard or soft exceptions.
FrameSoftError404ExceptioninFrameSoftErrorTest.phpwhich tests publishing a messages to a non existing exchange calledwhoops. You can play around with it by commenting out line 21 so that it shows the exception instead of testing against it.I'm happy to discuss and answer any questions.