Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is an initial PR for Issue #70 and handling of frame errors in general. #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Donatello-za
Copy link
Contributor

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:

  1. Three new "base" frame exception classes have been added:
  • FrameException extends BunnyException
  • FrameSoftErrorException extends FrameException
  • FrameHardErrorException extends FrameException
  1. The generator will generate all the soft error and hard error frame exceptions source code in the format:
    FrameHardError???Exception and FrameSoftError???Exception, these extend either FrameHardErrorException or FrameSoftErrorException depending on the error type. Examples are:
    FrameHardError320Exception and FrameSoftError404Exception

  2. The generator also generates a new class called FrameError under Bunny/Protocol. This class can determine and return the appropriate exception for any given frame. For example, in Channel.php on line 624 you have the following statement:

throw new ChannelException("Unhandled method frame " . get_class($frame) . ".");

This can be replaced with something like:

throw (new FrameError())->get($frame, 'Channel method frame error received.');

Which will throw the following exception if one attempts to publish a message to an exchange called whoops which 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 FrameError class 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.

  1. I added an initial test case for the FrameSoftError404Exception in FrameSoftErrorTest.php which tests publishing a messages to a non existing exchange called whoops. 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.

Donatello-za and others added 3 commits January 12, 2019 18:34
- 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.
@jakubkulhan jakubkulhan mentioned this pull request Jan 15, 2019
7 tasks
@jakubkulhan
Copy link
Owner

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 ChannelException for soft errors, and ConnectionException for hard errors with proper error message and error code from channel.close, or connection.close frames should be enough.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants