|
28 | 28 |
|
29 | 29 | NSString * const MatterInteractionErrorDomain = @"MatterInteractionErrorDomain";
|
30 | 30 |
|
| 31 | +// Class for holding on to a CHIP_ERROR that we can use as the value |
| 32 | +// in a dictionary. |
| 33 | +@interface CHIPErrorHolder : NSObject |
| 34 | +@property (nonatomic, readonly) CHIP_ERROR error; |
| 35 | + |
| 36 | +- (instancetype)init NS_UNAVAILABLE; |
| 37 | ++ (instancetype)new NS_UNAVAILABLE; |
| 38 | + |
| 39 | +- (instancetype)initWithError:(CHIP_ERROR)error; |
| 40 | +@end |
| 41 | + |
31 | 42 | @implementation CHIPError
|
32 | 43 |
|
33 | 44 | + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
|
@@ -75,15 +86,7 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
|
75 | 86 | }];
|
76 | 87 | }
|
77 | 88 |
|
78 |
| -#if CHIP_CONFIG_ERROR_SOURCE |
79 |
| - if (errorCode.GetFile()) { |
80 |
| - userInfo[@"errorFile"] = [NSString stringWithUTF8String:errorCode.GetFile()]; |
81 |
| - } |
82 |
| - |
83 |
| - if (errorCode.GetLine()) { |
84 |
| - userInfo[@"errorLine"] = @(errorCode.GetLine()); |
85 |
| - } |
86 |
| -#endif // CHIP_CONFIG_ERROR_SOURCE |
| 89 | + userInfo[@"underlyingError"] = [[CHIPErrorHolder alloc] initWithError:errorCode]; |
87 | 90 |
|
88 | 91 | return [NSError errorWithDomain:CHIPErrorDomain code:code userInfo:userInfo];
|
89 | 92 | ;
|
@@ -226,6 +229,13 @@ + (CHIP_ERROR)errorToCHIPErrorCode:(NSError * _Nullable)error
|
226 | 229 | return CHIP_ERROR_INTERNAL;
|
227 | 230 | }
|
228 | 231 |
|
| 232 | + if (error.userInfo != nil) { |
| 233 | + id underlyingError = error.userInfo[@"underlyingError"]; |
| 234 | + if (underlyingError != nil && [underlyingError isKindOfClass:[CHIPErrorHolder class]]) { |
| 235 | + return ((CHIPErrorHolder *) underlyingError).error; |
| 236 | + } |
| 237 | + } |
| 238 | + |
229 | 239 | chip::ChipError::StorageType code;
|
230 | 240 | switch (error.code) {
|
231 | 241 | case CHIPErrorCodeInvalidStringLength:
|
@@ -261,17 +271,21 @@ + (CHIP_ERROR)errorToCHIPErrorCode:(NSError * _Nullable)error
|
261 | 271 | }
|
262 | 272 | }
|
263 | 273 |
|
264 |
| - const char * file = nullptr; |
265 |
| - unsigned int line = 0; |
266 |
| - if (error.userInfo != nil) { |
267 |
| - if (error.userInfo[@"errorFile"] != nil) { |
268 |
| - file = [error.userInfo[@"errorFile"] cStringUsingEncoding:NSUTF8StringEncoding]; |
269 |
| - } |
270 |
| - if (error.userInfo[@"errorLine"] != nil) { |
271 |
| - line = [error.userInfo[@"errorLine"] unsignedIntValue]; |
272 |
| - } |
| 274 | + return chip::ChipError(code); |
| 275 | +} |
| 276 | + |
| 277 | +@end |
| 278 | + |
| 279 | +@implementation CHIPErrorHolder |
| 280 | + |
| 281 | +- (instancetype)initWithError:(CHIP_ERROR)error |
| 282 | +{ |
| 283 | + if (!(self = [super init])) { |
| 284 | + return nil; |
273 | 285 | }
|
274 |
| - return chip::ChipError(code, file, line); |
| 286 | + |
| 287 | + _error = error; |
| 288 | + return self; |
275 | 289 | }
|
276 | 290 |
|
277 | 291 | @end
|
0 commit comments