Skip to content

Commit 227c863

Browse files
committed
[Darwin] Guard CHIP source-file/line block under CHIP_CONFIG_ERROR_SOURCE
Per Copilot review on PR project-chip#72211: - ChipError::GetFile() / GetLine() are only defined when CHIP is built with CHIP_CONFIG_ERROR_SOURCE; builds with that flag disabled fail to compile. Wrap the source-info userInfo block under the same #if so the keys are simply absent on those builds. - Initialize legacyAdditionalUserInfo to nil at declaration. ARC zero-inits __strong locals already, but the explicit nil makes the contract clear.
1 parent 1c0a11c commit 227c863

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/darwin/Framework/CHIP/MTRError.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
8484

8585
MTRErrorCode code;
8686
NSString * description;
87-
NSDictionary * legacyAdditionalUserInfo;
87+
NSDictionary * legacyAdditionalUserInfo = nil;
8888
switch (errorCode.AsInteger()) {
8989
case CHIP_ERROR_INVALID_STRING_LENGTH.AsInteger():
9090
code = MTRErrorCodeInvalidStringLength;
@@ -170,6 +170,7 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
170170
// exposing build-host paths; only the basename is forwarded. Check both
171171
// forward and backward slashes so basename-stripping works on Windows builds
172172
// as well as Unix-style hosts.
173+
#if CHIP_CONFIG_ERROR_SOURCE
173174
const char * sourceFile = errorCode.GetFile();
174175
if (sourceFile != nullptr && sourceFile[0] != '\0') {
175176
const char * basename = strrchr(sourceFile, '/');
@@ -179,6 +180,7 @@ + (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
179180
userInfo[MTRCHIPErrorSourceFileKey] = @((basename != nullptr) ? basename + 1 : sourceFile);
180181
userInfo[MTRCHIPErrorSourceLineKey] = @(errorCode.GetLine());
181182
}
183+
#endif // CHIP_CONFIG_ERROR_SOURCE
182184

183185
if (legacyAdditionalUserInfo) {
184186
[userInfo addEntriesFromDictionary:legacyAdditionalUserInfo];

0 commit comments

Comments
 (0)