Skip to content

Commit 3cb6025

Browse files
Map CHIP_ERROR_FABRIC_EXISTS into a dedicated Darwin error code. (#22271)
This allows detection of this case without having to examine the "underlyingError" of the NSError's userInfo. Fixes #22214
1 parent 04eeef1 commit 3cb6025

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/darwin/Framework/CHIP/MTRError.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ FOUNDATION_EXPORT NSErrorDomain const MTRErrorDomain;
2323
FOUNDATION_EXPORT NSErrorDomain const MTRInteractionErrorDomain;
2424

2525
/**
26-
* ChipErrorDomain contains errors caused by data processing the framework
26+
* MTRErrorDomain contains errors caused by data processing the framework
2727
* itself is performing. These can be caused by invalid values provided to a
2828
* framework API, failure to decode an incoming message, and so forth.
2929
*
30-
* Errors reported by the other side of a Matter interaction use
31-
* MTRInteractionErrorDomain instead.
30+
* This error domain also contains errors that are communicated via success
31+
* responses from a server but mapped to an error on the client.
32+
*
33+
* Errors reported by the server side of a Matter interaction via the normal
34+
* Matter error-reporting mechanisms use MTRInteractionErrorDomain instead.
3235
*/
3336
// clang-format off
3437
typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
@@ -51,6 +54,11 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
5154
MTRErrorCodeIntegrityCheckFailed = 8,
5255
MTRErrorCodeTimeout = 9,
5356
MTRErrorCodeBufferTooSmall = 10,
57+
/**
58+
* MTRErrorCodeFabricExists is returned when trying to commission a device
59+
* into a fabric when it's already part of that fabric.
60+
*/
61+
MTRErrorCodeFabricExists = 11,
5462
};
5563
// clang-format on
5664

src/darwin/Framework/CHIP/MTRError.mm

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
8080
} else if (errorCode == CHIP_ERROR_BUFFER_TOO_SMALL) {
8181
code = MTRErrorCodeBufferTooSmall;
8282
[userInfo addEntriesFromDictionary:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"A buffer is too small.", nil) }];
83+
} else if (errorCode == CHIP_ERROR_FABRIC_EXISTS) {
84+
code = MTRErrorCodeFabricExists;
85+
[userInfo addEntriesFromDictionary:@{
86+
NSLocalizedDescriptionKey : NSLocalizedString(@"The device is already a member of this fabric.", nil)
87+
}];
8388
} else {
8489
code = MTRErrorCodeGeneralError;
8590
[userInfo addEntriesFromDictionary:@{

0 commit comments

Comments
 (0)