Skip to content

Commit 4072723

Browse files
Better error reporting for missing build setting info subpaths
- Add error codes for overall and underlying error - Add function to return underlying error key for pre-11.3 - Add category factory method to NSError for subpaths not found error - Rework -loadBuildSettingInfo method to return error - Move to new version of -loadBuildSettingInfo in code and test
1 parent 591ac2d commit 4072723

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

BuildSettingExtractor/BuildSettingCommentGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
- (NSString *)commentForBuildSettingWithName:(NSString *)buildSettingName;
1818

19-
- (BOOL)loadBuildSettingInfo; // Primarily for testing
19+
- (BOOL)loadBuildSettingInfo:(NSError **)error; // In public interface for testing
2020

2121
@end

BuildSettingExtractor/BuildSettingCommentGenerator.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ - (NSString *)commentForBuildSettingWithName:(NSString *)buildSettingName {
7070

7171
- (NSString *)presentationNameForKey:(NSString *)key {
7272
if (!self.buildSettingInfoDictionary) {
73-
[self loadBuildSettingInfo];
73+
[self loadBuildSettingInfo:nil];
7474
}
7575

7676
NSString *processedKey = [key tps_baseBuildSettingName]; // strip any conditional part of build setting
@@ -81,7 +81,7 @@ - (NSString *)presentationNameForKey:(NSString *)key {
8181

8282
- (NSString *)descriptionForKey:(NSString *)key {
8383
if (!self.buildSettingInfoDictionary) {
84-
[self loadBuildSettingInfo];
84+
[self loadBuildSettingInfo:nil];
8585
}
8686

8787
NSString *processedKey = [key tps_baseBuildSettingName]; // strip any conditional part of build setting
@@ -156,9 +156,10 @@ - (NSString *)processedDescriptionString:(NSString *)string forKey:(NSString *)k
156156
return processedString;
157157
}
158158

159-
- (BOOL)loadBuildSettingInfo {
159+
// Returns an array of error strings describing unread build setting info files
160+
- (BOOL)loadBuildSettingInfo:(NSError **)error {
160161

161-
BOOL allSubpathsReadSuccessfully = YES;
162+
NSMutableArray *subpathReadingErrorStrings = [[NSMutableArray alloc] init];
162163

163164
NSString *defaultXcodePath = self.infoSource.resolvedURL.path;
164165
NSInteger xcodeVersion = self.infoSource.resolvedVersion;
@@ -230,20 +231,27 @@ - (BOOL)loadBuildSettingInfo {
230231
}
231232
}
232233
if (!foundOne) {
234+
NSString *errorString = nil;
233235
if (buildSettingInfoSubpathList.count == 0) {
234-
NSLog(@"Empty array of subpaths at index %lu", [buildSettingInfoSubpaths indexOfObject:buildSettingInfoSubpathList]);
236+
errorString = [NSString stringWithFormat: @"Empty array of subpaths at index %lu", [buildSettingInfoSubpaths indexOfObject:buildSettingInfoSubpathList]];
235237
} else if (buildSettingInfoSubpathList.count == 1) {
236-
NSLog(@"Could not read settings strings at path: %@", buildSettingInfoSubpathList[0]);
238+
errorString = [NSString stringWithFormat:@"Could not read settings strings at path: %@", buildSettingInfoSubpathList[0]];
237239
} else {
238-
NSLog(@"Could not read settings strings at these paths: %@", buildSettingInfoSubpathList);
240+
errorString = [NSString stringWithFormat:@"Could not read settings strings at these paths: %@", buildSettingInfoSubpathList];
239241
}
240-
allSubpathsReadSuccessfully = NO;
242+
[subpathReadingErrorStrings addObject:errorString];
241243
}
242244
}
243245

244246
_buildSettingInfoDictionary = infoStringFile;
247+
248+
BOOL success = subpathReadingErrorStrings.count == 0;
249+
250+
if (!success && error) {
251+
*error = [NSError errorForSettingInfoFilesNotFound:subpathReadingErrorStrings];
252+
}
245253

246-
return allSubpathsReadSuccessfully;
254+
return success;
247255
}
248256

249257
- (NSDictionary *)xcspecFileBuildSettingInfoForPath:(NSString *)path {

BuildSettingExtractor/Constants+Categories.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ typedef NS_ENUM(NSUInteger, BuildSettingExtractorErrorCodes) {
1414
ProjectSettingsNamingConflict = 102,
1515
NoSettingsFoundInProjectFile = 103,
1616
BuildSettingInfoSourceNotFound = 104,
17+
BuildSettingInfoFilesNotFound = 105,
18+
BuildSettingInfoSubpathNotFound = 106,
1719
};
1820

1921
extern NSErrorDomain const TPSBuildSettingExtractorErrorDomain;
22+
extern NSString * TPSMultipleUnderlyingErrorsKey(void);
2023

2124
#pragma mark -
2225

@@ -62,6 +65,10 @@ extern NSErrorDomain const TPSBuildSettingExtractorErrorDomain;
6265
// Notify the user the destination folder already contains build config files
6366
+ (NSError *)errorForDestinationContainsBuildConfigFiles;
6467

68+
// Error that one or more expected build setting info files were not found
69+
// User info includes NSMultipleUnderlyingErrorsKey to report underlying errors
70+
+ (NSError *)errorForSettingInfoFilesNotFound:(NSArray *)subpathErrorStrings;
71+
6572
@end
6673

6774
#pragma mark -

BuildSettingExtractor/Constants+Categories.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,35 @@ + (NSError *)errorForDestinationContainsBuildConfigFiles {
134134
return error;
135135
}
136136

137+
+ (NSError *)errorForSettingInfoFilesNotFound:(NSArray *)subpathErrorStrings {
138+
if (subpathErrorStrings.count == 0) {
139+
[NSException raise:NSInternalInconsistencyException format:@"Attempt to create BuildSettingInfoSubpathNotFound error with no underlying errors"];
140+
}
141+
NSMutableArray *underlyingErrors = [[NSMutableArray alloc] init];
142+
for (NSString *errorString in subpathErrorStrings) {
143+
NSDictionary *subpathErrorUserInfo = @{NSLocalizedDescriptionKey:errorString};
144+
NSError *subpathError = [NSError errorWithDomain:TPSBuildSettingExtractorErrorDomain code:BuildSettingInfoSubpathNotFound userInfo:subpathErrorUserInfo];
145+
[underlyingErrors addObject:subpathError];
146+
}
147+
148+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:@"Some build info files not found.", TPSMultipleUnderlyingErrorsKey():underlyingErrors};
149+
150+
NSError *error = [NSError errorWithDomain:TPSBuildSettingExtractorErrorDomain code:BuildSettingInfoFilesNotFound userInfo:userInfo];
151+
152+
return error;
153+
}
154+
137155
@end
138156

157+
// Can remove once deployment target is macOS 11.3 or later
158+
NSString * TPSMultipleUnderlyingErrorsKey() {
159+
if (@available(macOS 11.3, *)) {
160+
return NSMultipleUnderlyingErrorsKey;
161+
} else {
162+
return @"NSMultipleUnderlyingErrorsKey";
163+
}
164+
}
165+
139166
#pragma mark -
140167

141168
@implementation EmptyStringTransformer

BuildSettingExtractorTests/BuildSettingExtractorTests.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ - (void)testLoadingBuildSettingInfo
6464
XCTAssertNil(error);
6565

6666
BuildSettingCommentGenerator *commentGenerator = [[BuildSettingCommentGenerator alloc] initWithBuildSettingInfoSource:infoSource];
67-
XCTAssertTrue([commentGenerator loadBuildSettingInfo]);
68-
67+
BOOL success = [commentGenerator loadBuildSettingInfo:&error];
68+
XCTAssertTrue(success);
69+
XCTAssertNil(error);
6970
}
7071

7172
- (void)testBadProjectURL

0 commit comments

Comments
 (0)