Skip to content

Commit

Permalink
Map CHIP_ERROR_FABRIC_EXISTS into a dedicated Darwin error code. (pro…
Browse files Browse the repository at this point in the history
…ject-chip#22271)

This allows detection of this case without having to examine the
"underlyingError" of the NSError's userInfo.

Fixes project-chip#22214
  • Loading branch information
bzbarsky-apple authored and isiu-apple committed Sep 16, 2022
1 parent 9834521 commit 0829018
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/darwin/Framework/CHIP/MTRError.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ FOUNDATION_EXPORT NSErrorDomain const MTRErrorDomain;
FOUNDATION_EXPORT NSErrorDomain const MTRInteractionErrorDomain;

/**
* ChipErrorDomain contains errors caused by data processing the framework
* MTRErrorDomain contains errors caused by data processing the framework
* itself is performing. These can be caused by invalid values provided to a
* framework API, failure to decode an incoming message, and so forth.
*
* Errors reported by the other side of a Matter interaction use
* MTRInteractionErrorDomain instead.
* This error domain also contains errors that are communicated via success
* responses from a server but mapped to an error on the client.
*
* Errors reported by the server side of a Matter interaction via the normal
* Matter error-reporting mechanisms use MTRInteractionErrorDomain instead.
*/
// clang-format off
typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
Expand All @@ -51,6 +54,11 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
MTRErrorCodeIntegrityCheckFailed = 8,
MTRErrorCodeTimeout = 9,
MTRErrorCodeBufferTooSmall = 10,
/**
* MTRErrorCodeFabricExists is returned when trying to commission a device
* into a fabric when it's already part of that fabric.
*/
MTRErrorCodeFabricExists = 11,
};
// clang-format on

Expand Down
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/MTRError.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
} else if (errorCode == CHIP_ERROR_BUFFER_TOO_SMALL) {
code = MTRErrorCodeBufferTooSmall;
[userInfo addEntriesFromDictionary:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"A buffer is too small.", nil) }];
} else if (errorCode == CHIP_ERROR_FABRIC_EXISTS) {
code = MTRErrorCodeFabricExists;
[userInfo addEntriesFromDictionary:@{
NSLocalizedDescriptionKey : NSLocalizedString(@"The device is already a member of this fabric.", nil)
}];
} else {
code = MTRErrorCodeGeneralError;
[userInfo addEntriesFromDictionary:@{
Expand Down

0 comments on commit 0829018

Please sign in to comment.