Skip to content

Commit

Permalink
Improve error reporting when DNS-SD lookups are denied on Darwin. (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jan 4, 2024
1 parent c56980e commit 1473848
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/darwin/Framework/CHIP/MTRError.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
* TLV-level failures.
*/
MTRErrorCodeTLVDecodeFailed MTR_AVAILABLE(ios(17.0), macos(14.0), watchos(10.0), tvos(17.0)) = 14,

/**
* MTRErrorCodeDNSSDUnauthorized means that the application is not
* authorized to perform DNS_SD lookups. This typically means missing
* entries for "_matter._tcp" (for operational lookup) and "_matterc._udp"
* (for commissionable lookup) under the NSBonjourServices key in the
* application's Info.plist.
*/
MTRErrorCodeDNSSDUnauthorized MTR_NEWLY_AVAILABLE = 15,
};
// clang-format on

Expand Down
12 changes: 12 additions & 0 deletions src/darwin/Framework/CHIP/MTRError.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
} else if (errorCode == CHIP_ERROR_DECODE_FAILED) {
code = MTRErrorCodeTLVDecodeFailed;
[userInfo addEntriesFromDictionary:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"TLV decoding failed.", nil) }];
} else if (errorCode == CHIP_ERROR_DNS_SD_UNAUTHORIZED) {
code = MTRErrorCodeDNSSDUnauthorized;
[userInfo addEntriesFromDictionary:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"Access denied to perform DNS-SD lookups. Check that \"_matter._tcp\" and/or \"_matterc._udp\" are listed under the NSBonjourServices key in Info.plist", nil) }];
} else {
code = MTRErrorCodeGeneralError;
[userInfo addEntriesFromDictionary:@{
Expand Down Expand Up @@ -282,6 +285,15 @@ + (CHIP_ERROR)errorToCHIPErrorCode:(NSError * _Nullable)error
case MTRErrorCodeBufferTooSmall:
code = CHIP_ERROR_BUFFER_TOO_SMALL.AsInteger();
break;
case MTRErrorCodeFabricExists:
code = CHIP_ERROR_FABRIC_EXISTS.AsInteger();
break;
case MTRErrorCodeTLVDecodeFailed:
code = CHIP_ERROR_DECODE_FAILED.AsInteger();
break;
case MTRErrorCodeDNSSDUnauthorized:
code = CHIP_ERROR_DNS_SD_UNAUTHORIZED.AsInteger();
break;
case MTRErrorCodeGeneralError: {
if (error.userInfo != nil && error.userInfo[@"errorCode"] != nil) {
code = static_cast<decltype(code)>([error.userInfo[@"errorCode"] unsignedLongValue]);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,15 @@ using CHIP_ERROR = ::chip::ChipError;

// AVAILABLE: 0xb1
// AVAILABLE: 0xb2
// AVAILABLE: 0xb3

/**
* @def CHIP_ERROR_DNS_SD_UNAUTHORIZED
*
* @brief
* The application is not authorized to do DNS_SD lookups.
*
*/
#define CHIP_ERROR_DNS_SD_UNAUTHORIZED CHIP_CORE_ERROR(0xb3)

/**
* @def CHIP_ERROR_MDNS_COLLISION
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Darwin/MdnsError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ CHIP_ERROR ToChipError(DNSServiceErrorType errorCode)
return CHIP_ERROR_MDNS_COLLISION;
case kDNSServiceErr_NoMemory:
return CHIP_ERROR_NO_MEMORY;
case kDNSServiceErr_NoAuth:
return CHIP_ERROR_DNS_SD_UNAUTHORIZED;
default:
return CHIP_ERROR_INTERNAL;
}
Expand Down

0 comments on commit 1473848

Please sign in to comment.