-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[ASDisplayNode] Add support for setting non-fatal error block #2993
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.
Should we make a new macro which is called ASNonFatalAssert? In which case it would need to create an error from the assert and call this automatically?
AsyncDisplayKit/ASDisplayNode.h
Outdated
@@ -53,6 +53,12 @@ typedef void (^ASDisplayNodeContextModifier)(_Nonnull CGContextRef context); | |||
typedef ASLayoutSpec * _Nonnull(^ASLayoutSpecBlock)(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize); | |||
|
|||
/** | |||
* AsyncDisplayKit non-faltal error block. This block can be used for handling non-fatal errors. Useful for reporting |
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.
Typo: "non-faltal"
AsyncDisplayKit/ASDisplayNode.h
Outdated
@@ -256,6 +262,15 @@ NS_ASSUME_NONNULL_BEGIN | |||
*/ | |||
@property (readonly) ASInterfaceState interfaceState; | |||
|
|||
/** | |||
* @abstract Class property that allows to set a block that can be called on non-fatal errors. This | |||
* property can be useful for cases when Async Display Kit can recover from an anormal behavior, but |
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.
typo: "anormal"
AsyncDisplayKit/ASDisplayNode.h
Outdated
/** | ||
* @abstract Class property that allows to set a block that can be called on non-fatal errors. This | ||
* property can be useful for cases when Async Display Kit can recover from an anormal behavior, but | ||
* still gives the opportunity to use a reporting mechanism to catch occurrences in production. |
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.
Maybe add: "In development, ASDK will assert instead of calling this."
Jenkins, add to whitelist |
Base/ASAssert.h
Outdated
@@ -59,3 +59,17 @@ | |||
#define ASDisplayNodeCAssertPositiveReal(description, num) ASDisplayNodeCAssert(num >= 0 && num <= CGFLOAT_MAX, @"%@ must be a real positive integer.", description) | |||
#define ASDisplayNodeCAssertInfOrPositiveReal(description, num) ASDisplayNodeCAssert(isinf(num) || (num >= 0 && num <= CGFLOAT_MAX), @"%@ must be infinite or a real positive integer.", description) | |||
|
|||
#define ASDisplayNodeErrorDomain @"ASDisplayNodeErrorDomain" | |||
#define ASDisplayNodeNonFatalErrorCode 0 |
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.
Total nit, but maybe make this 1
? Many systems use zero as a non-error.
Base/ASAssert.h
Outdated
#define ASDisplayNodeNonFatalErrorCode 0 | ||
|
||
#define ASDisplayNodeAssertNonFatal(desc, ...) \ | ||
ASDisplayNodeAssert(NO, desc, ##__VA_ARGS__); \ |
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 thinking more along the lines of this above
#define ASDisplayNodeAssertNonFatal(condition, desc, ...)
ASDisplayNodeAssert(condition, desc, ##__VA_ARGS__);
if (condition) {
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.
Thank you for putting this up Rocir!
Currently Async Display Kit doesn't provide a mechanism for "asserting" in production. In many the framework can recover from failures, but that would happen silently when in production.
This code changes gives the ability to set a "non-fatal error block" on
ASDisplayNode
class, so it can be plugged in many areas where we have asserts, for example, so developers have the change to capture and report such failures in production.This addresses #2807 .