Skip to content

Commit 69d19f2

Browse files
committed
More error handling when parsing book.json
When the JSON contains a duplicate key, JSONObjectWithData on iOS 5.1 will return nil. Unfortunately, the returned error is not very helpful, but it's at least better than the previous version of the code (which was printing the error in the wrong place). See Simbul#904.
1 parent 21d5210 commit 69d19f2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

BakerView/BakerBook.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,18 @@ - (id)initWithBookJSONPath:(NSString *)bookJSONPath
107107

108108
NSError* error = nil;
109109
NSData* bookJSON = [NSData dataWithContentsOfFile:bookJSONPath options:0 error:&error];
110-
// TODO: errror handling
110+
if (error) {
111+
NSLog(@"[BakerBook] ERROR reading 'book.json': %@", error.localizedDescription);
112+
return nil;
113+
}
114+
111115
NSDictionary* bookData = [NSJSONSerialization JSONObjectWithData:bookJSON
112116
options:0
113117
error:&error];
114-
// TODO: deal with error
118+
if (error) {
119+
NSLog(@"[BakerBook] ERROR parsing 'book.json': %@", error.localizedDescription);
120+
return nil;
121+
}
115122

116123
return [self initWithBookData:bookData];
117124
}

0 commit comments

Comments
 (0)