Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Message envelope and uncaught exceptions #104

Open
abhinav opened this issue Jan 12, 2016 · 2 comments
Open

Message envelope and uncaught exceptions #104

abhinav opened this issue Jan 12, 2016 · 2 comments

Comments

@abhinav
Copy link
Contributor

abhinav commented Jan 12, 2016

We need a way to handle uncaught exceptions. Thrift uses the following shape for internal exceptions.

enum ExceptionType {
  UNKNOWN = 0
  UNKNOWN_METHOD = 1
  INVALID_MESSAGE_TYPE = 2
  WRONG_METHOD_NAME = 3
  BAD_SEQUENCE_ID = 4
  MISSING_RESULT = 5
  INTERNAL_ERROR = 6
  PROTOCOL_ERROR = 7
  INVALID_TRANSFORM = 8
  INVALID_PROTOCOL = 9
  UNSUPPORTED_CLIENT_TYPE = 10
}

struct TApplicationException {
  1: optional string message
  2: optional ExceptionType type
}

We need to be able to send messages with that as the payload and EXCEPTION as the message type.

@abhinav
Copy link
Contributor Author

abhinav commented Jan 12, 2016

Proposal: We call it InternalApplicationError or something similar that is more obvious than TApplicationException. It is simple enough to make message.dumps and message.loads support it. (Right now, message.loads treats this as an unknown exception and raises an exception with the Value-level representation).

import thriftrw
from thriftrw.something import InternalApplicationError  # something or just top-level TBD

myservice = thriftrw.load(..)
payload = myservice.dumps.message(InternalApplicationError(..), seqid=42)

message = myservice.loads.message(myservice.SomeService, payload)
assert message.message_type == mtype.EXCEPTION
raise message.body

The Client/Server API in #103 will need to support this too.

@abhinav
Copy link
Contributor Author

abhinav commented Jan 13, 2016

Actually, the EXCEPTION message still needs the method name.

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

No branches or pull requests

1 participant