Skip to content
Snippets Groups Projects
  • Mark McLoughlin's avatar
    f6df32d9
    Add API for expected endpoint exceptions · f6df32d9
    Mark McLoughlin authored
    Review I4e7b19dc730342091fd70a717065741d56da4555 gives a lot of the
    background here, but the idea is that some exceptions raised by an RPC
    endpoint method do not indicate any sort of failure and should not be
    logged by the server as an error.
    
    The classic example of this is conductor's instance_get() method raising
    InstanceNotFound. This is perfectly normal and should not be considered
    an error.
    
    The new API is a decorator which you can use with RPC endpoints methods
    to indicate which exceptions are expected:
    
        @messaging.expected_exceptions(InstanceNotFound)
        def instance_get(self, context, instance_id):
            ...
    
    but we also need to expose the ExpectedException type itself so that
    direct "local" users of the endpoint class know what type will be used
    to wrap expected exceptions. For example, Nova has an ExceptionHelper
    class which unwraps the original exception from an ExpectedException and
    re-raises it.
    
    I've changed from client_exceptions() and ClientException to make it
    more clear it's intent. I felt that the "client" naming gave the
    impression it was intended for use on the client side.
    
    Change-Id: Ieec4600bd6b70cf31ac7925a98a517b84acada4d
    f6df32d9
    History
    Add API for expected endpoint exceptions
    Mark McLoughlin authored
    Review I4e7b19dc730342091fd70a717065741d56da4555 gives a lot of the
    background here, but the idea is that some exceptions raised by an RPC
    endpoint method do not indicate any sort of failure and should not be
    logged by the server as an error.
    
    The classic example of this is conductor's instance_get() method raising
    InstanceNotFound. This is perfectly normal and should not be considered
    an error.
    
    The new API is a decorator which you can use with RPC endpoints methods
    to indicate which exceptions are expected:
    
        @messaging.expected_exceptions(InstanceNotFound)
        def instance_get(self, context, instance_id):
            ...
    
    but we also need to expose the ExpectedException type itself so that
    direct "local" users of the endpoint class know what type will be used
    to wrap expected exceptions. For example, Nova has an ExceptionHelper
    class which unwraps the original exception from an ExpectedException and
    re-raises it.
    
    I've changed from client_exceptions() and ClientException to make it
    more clear it's intent. I felt that the "client" naming gave the
    impression it was intended for use on the client side.
    
    Change-Id: Ieec4600bd6b70cf31ac7925a98a517b84acada4d
test_expected_exceptions.py 1.69 KiB