Skip to content

Commit 749d73a

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Improve error reporting when DNS-SD lookups are denied on Darwin. (#29642)
1 parent a07e50a commit 749d73a

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/darwin/Framework/CHIP/MTRError.h

+9
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
7878
* TLV-level failures.
7979
*/
8080
MTRErrorCodeTLVDecodeFailed MTR_AVAILABLE(ios(17.0), macos(14.0), watchos(10.0), tvos(17.0)) = 14,
81+
82+
/**
83+
* MTRErrorCodeDNSSDUnauthorized means that the application is not
84+
* authorized to perform DNS_SD lookups. This typically means missing
85+
* entries for "_matter._tcp" (for operational lookup) and "_matterc._udp"
86+
* (for commissionable lookup) under the NSBonjourServices key in the
87+
* application's Info.plist.
88+
*/
89+
MTRErrorCodeDNSSDUnauthorized MTR_NEWLY_AVAILABLE = 15,
8190
};
8291
// clang-format on
8392

src/darwin/Framework/CHIP/MTRError.mm

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
9595
} else if (errorCode == CHIP_ERROR_DECODE_FAILED) {
9696
code = MTRErrorCodeTLVDecodeFailed;
9797
[userInfo addEntriesFromDictionary:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"TLV decoding failed.", nil) }];
98+
} else if (errorCode == CHIP_ERROR_DNS_SD_UNAUTHORIZED) {
99+
code = MTRErrorCodeDNSSDUnauthorized;
100+
[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) }];
98101
} else {
99102
code = MTRErrorCodeGeneralError;
100103
[userInfo addEntriesFromDictionary:@{
@@ -282,6 +285,15 @@ + (CHIP_ERROR)errorToCHIPErrorCode:(NSError * _Nullable)error
282285
case MTRErrorCodeBufferTooSmall:
283286
code = CHIP_ERROR_BUFFER_TOO_SMALL.AsInteger();
284287
break;
288+
case MTRErrorCodeFabricExists:
289+
code = CHIP_ERROR_FABRIC_EXISTS.AsInteger();
290+
break;
291+
case MTRErrorCodeTLVDecodeFailed:
292+
code = CHIP_ERROR_DECODE_FAILED.AsInteger();
293+
break;
294+
case MTRErrorCodeDNSSDUnauthorized:
295+
code = CHIP_ERROR_DNS_SD_UNAUTHORIZED.AsInteger();
296+
break;
285297
case MTRErrorCodeGeneralError: {
286298
if (error.userInfo != nil && error.userInfo[@"errorCode"] != nil) {
287299
code = static_cast<decltype(code)>([error.userInfo[@"errorCode"] unsignedLongValue]);

src/lib/core/CHIPError.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,15 @@ using CHIP_ERROR = ::chip::ChipError;
14491449

14501450
// AVAILABLE: 0xb1
14511451
// AVAILABLE: 0xb2
1452-
// AVAILABLE: 0xb3
1452+
1453+
/**
1454+
* @def CHIP_ERROR_DNS_SD_UNAUTHORIZED
1455+
*
1456+
* @brief
1457+
* The application is not authorized to do DNS_SD lookups.
1458+
*
1459+
*/
1460+
#define CHIP_ERROR_DNS_SD_UNAUTHORIZED CHIP_CORE_ERROR(0xb3)
14531461

14541462
/**
14551463
* @def CHIP_ERROR_MDNS_COLLISION

src/platform/Darwin/MdnsError.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ CHIP_ERROR ToChipError(DNSServiceErrorType errorCode)
104104
return CHIP_ERROR_MDNS_COLLISION;
105105
case kDNSServiceErr_NoMemory:
106106
return CHIP_ERROR_NO_MEMORY;
107+
case kDNSServiceErr_NoAuth:
108+
return CHIP_ERROR_DNS_SD_UNAUTHORIZED;
107109
default:
108110
return CHIP_ERROR_INTERNAL;
109111
}

0 commit comments

Comments
 (0)