From e34c09182ebe0ed2958aefa809159498923743d3 Mon Sep 17 00:00:00 2001 From: Sergio Campamá Date: Thu, 2 Jun 2016 11:14:26 -0700 Subject: Improving the granularity parsing errors (#1623) Add more context to GPBCodedInputStream failures. Have GPBMessage parsing apis extract out the GPBCodedInputStream information and expose it. Update HeaderDocs with pointers to all error domains/codes. Expand the unittests to cover the full set of errors reported. Fixes https://github.com/google/protobuf/issues/1618 --- objectivec/GPBMessage.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'objectivec/GPBMessage.h') diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index 2249829f..b3b07793 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -49,12 +49,15 @@ extern NSString *const GPBMessageErrorDomain; /// Error code for NSError with GPBMessageErrorDomain. typedef NS_ENUM(NSInteger, GPBMessageErrorCode) { - /// The data being parsed is bad and a message can not be created from it. - GPBMessageErrorCodeMalformedData = -100, + /// Uncategorized error. + GPBMessageErrorCodeOther = -100, /// A message can't be serialized because it is missing required fields. GPBMessageErrorCodeMissingRequiredField = -101, }; +/// Key under which the error's reason is stored inside the userInfo dictionary. +extern NSString *const GPBErrorReasonKey; + CF_EXTERN_C_END /// Base class for all of the generated message classes. @@ -86,6 +89,9 @@ CF_EXTERN_C_END /// @note In DEBUG builds, the parsed message is checked to be sure all required /// fields were provided, and the parse will fail if some are missing. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param data The data to parse. /// @param errorPtr An optional error pointer to fill in with a failure reason if /// the data can not be parsed. @@ -101,6 +107,9 @@ CF_EXTERN_C_END /// @note In DEBUG builds, the parsed message is checked to be sure all required /// fields were provided, and the parse will fail if some are missing. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param data The data to parse. /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure @@ -119,6 +128,9 @@ CF_EXTERN_C_END /// @note In DEBUG builds, the parsed message is checked to be sure all required /// fields were provided, and the parse will fail if some are missing. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param input The stream to read data from. /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure @@ -139,6 +151,9 @@ CF_EXTERN_C_END /// the required fields are set. So this method can be used to reload /// messages that may not be complete. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param input The stream to read data from. /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure @@ -158,6 +173,9 @@ CF_EXTERN_C_END /// @note In DEBUG builds, the parsed message is checked to be sure all required /// fields were provided, and the parse will fail if some are missing. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param data The data to parse. /// @param errorPtr An optional error pointer to fill in with a failure reason if /// the data can not be parsed. @@ -171,6 +189,9 @@ CF_EXTERN_C_END /// @note In DEBUG builds, the parsed message is checked to be sure all required /// fields were provided, and the parse will fail if some are missing. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param data The data to parse. /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure @@ -188,6 +209,9 @@ CF_EXTERN_C_END /// the required fields are set. So this method can be used to reload /// messages that may not be complete. /// +/// @note The errors returned are likely coming from the domain and codes listed +/// at the top of this file and GPBCodedInputStream.h. +/// /// @param input The stream to read data from. /// @param extensionRegistry The extension registry to use to look up extensions. /// @param errorPtr An optional error pointer to fill in with a failure -- cgit v1.2.3