Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting when DNS-SD lookups are denied on Darwin. #29642

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading