Skip to content

Commit

Permalink
[darwin-framework-tool] Just send a message to read the MTRErrorHolde…
Browse files Browse the repository at this point in the history
…r value instead of duplicating the class interface (#22811)
  • Loading branch information
vivien-apple authored Sep 22, 2022
1 parent 7189344 commit ca0dd9b
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions examples/darwin-framework-tool/commands/common/MTRError.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@
#import <inet/InetError.h>
#import <lib/support/TypeTraits.h>

// Stolen for now from the framework, need to export this properly.
@interface DFTErrorHolder : NSObject
@property (nonatomic, readonly) CHIP_ERROR error;
@end

@implementation DFTErrorHolder

- (instancetype)initWithError:(CHIP_ERROR)error
{
if (!(self = [super init])) {
return nil;
}

_error = error;
return self;
}

@end

CHIP_ERROR MTRErrorToCHIPErrorCode(NSError * error)
{
if (error == nil) {
Expand All @@ -64,8 +45,13 @@ CHIP_ERROR MTRErrorToCHIPErrorCode(NSError * error)

if (error.userInfo != nil) {
id underlyingError = error.userInfo[@"underlyingError"];
if (underlyingError != nil && [underlyingError isKindOfClass:[DFTErrorHolder class]]) {
return ((DFTErrorHolder *) underlyingError).error;
if (underlyingError != nil) {
NSValue * chipErrorValue = [underlyingError valueForKey:@"error"];
if (chipErrorValue != nil) {
CHIP_ERROR chipError;
[chipErrorValue getValue:&chipError];
return chipError;
}
}
}

Expand Down

0 comments on commit ca0dd9b

Please sign in to comment.