alanxz/rabbitmq-c — pull request #118 by alanxz (2013-05-26 07:38:28+00:00)
Title: Improve error code interface

The purpose of this is to improve the usability of the error codes returned by the public interface of the library.

Currently for certain functions the library returns an `int` which indicates success or failure, and in the case of failure it opaquely encodes the reason why the functioned failed. The `amqp_error_string()` function can then be used to retrieve a human readable string describing the error, but there has been no way to examine this error code programically.

This attempts to provide publicly-consumable error codes.

Things this PR should probably address, but doesn't (yet):
- Detailed information about `getaddrinfo()` failure beyond `AMQP_STATUS_GETHOSTBYNAME_FAILED`. All that required here is to examine the various things `getaddrinfo()` can return and map that to something usable by the user.
- Detailed information about various socket failures beyond `AMQP_STATUS_SOCKET_ERROR`. This requires examining `errno` or `WSAGetLastFailure()` on Win32 and mapping it to something useful to the user
- Detailed information about SSL failures beyond `AMQP_STATUS_SSL_ERROR`. This is quite a bit more complex as OpenSSL doesn't have a single value - it could be a whole stack of values

Other thoughts:
- We don't need to (nor do we want to) propagate all of the raw errors up to the user. It is unlikely to be useful to the user in the general case.
- On the other hand it can be extremely useful to get the underlying error code(s) when debugging things like SSL, where the reason for failure can be quite complex.

@msteinert - I know you had some thoughts on the error API, care to share them?