-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Standardize exception definitions #12583
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see these changes!
The only comment I have is: should the exception names be of the form MGLException<Name>
? So MGLExceptionAbstractClass
instead of MGLAbstractClassException
?
(This makes sense to me when I think of it in terms of calling our |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a master header with all the exceptions, we will declare on each file the exceptions it throws (if any)? If so, should we document this?
@julianrex and I were curious about how this ended up looking in Swift, so: |
platform/darwin/src/MGLTypes.h
Outdated
@@ -30,6 +30,11 @@ NS_ASSUME_NONNULL_BEGIN | |||
typedef NSString *NSNotificationName; | |||
#endif | |||
|
|||
typedef NSString *MGLExceptionName NS_EXTENSIBLE_STRING_ENUM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was copying NSExceptionName
, but I’m going to look at replacing this with NS_TYPED_EXTENSIBLE_ENUM
on Apple’s recommendation:
You might encounter Objective-C code that uses the older
NS_STRING_ENUM
andNS_EXTENSIBLE_STRING_ENUM
macros, which were used to group string constants. UseNS_TYPED_ENUM
andNS_TYPED_EXTENSIBLE_ENUM
when grouping related constants of any type, including string constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xcode 9 has all of these defined as the same thing, so it’s just cosmetic:
#define NS_STRING_ENUM _NS_TYPED_ENUM
#define NS_EXTENSIBLE_STRING_ENUM _NS_TYPED_EXTENSIBLE_ENUM
#define NS_TYPED_ENUM _NS_TYPED_ENUM
#define NS_TYPED_EXTENSIBLE_ENUM _NS_TYPED_EXTENSIBLE_ENUM
... but let’s still standardize on the new one.
Defining non-generic constants close to their main usage sites is generally a good practice, I think, and is something we’ve been doing with other constants, like |
eae1570
to
2c18acb
Compare
@@ -6296,8 +6301,8 @@ - (void)setStyleURL__:(nullable NSString *)URLString | |||
NSURL *url = URLString.length ? [NSURL URLWithString:URLString] : nil; | |||
if (URLString.length && !url) | |||
{ | |||
[NSException raise:@"Invalid style URL" format: | |||
@"“%@” is not a valid style URL.", URLString]; | |||
[NSException raise:MGLInvalidStyleURLException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12640 takes care of the macOS side of this change.
Fixes #7258 by converting stringly-typed exception names into
MGLExceptionName
-typed constants. This doesn’t attempt to document the exceptions, but that could happen in the future./cc @1ec5 @fabian-guerra @julianrex @captainbarbosa