Patch/error handling
Based off of Michael Ellis' fixes for crashes when the calls to encode fail based on a type in the message fields.
Based off of Michael Ellis' fixes for crashes when the calls to encode fail based on a type in the message fields.