Skip to content

Commit 7b2827d

Browse files
committed
Harden against nil objects
This happens if a favorited contact get's archived, this would trigger an exception.
1 parent d05472c commit 7b2827d

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

DocumentAPI/OGoContacts/SkyEnterpriseDocument.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,45 @@ - (SkyDocumentType *)documentType {
148148
- (EODataSource *)personDataSource {
149149
SkyEnterprisePersonDataSource *ds;
150150

151+
if (self->globalID == nil) {
152+
[self logWithFormat:
153+
@"WARNING: no globalID for person datasource"];
154+
return nil;
155+
}
156+
151157
ds = [SkyEnterprisePersonDataSource alloc]; // keep gcc happy
152-
ds = [ds initWithContext:[self context] enterpriseId:[self globalID]];
158+
ds = [ds initWithContext:[self context]
159+
enterpriseId:[self globalID]];
153160
return [ds autorelease];
154161
}
155162

156163
- (EODataSource *)projectDataSource {
157164
SkyEnterpriseProjectDataSource *ds;
158165

166+
if (self->globalID == nil) {
167+
[self logWithFormat:
168+
@"WARNING: no globalID for project datasource"];
169+
return nil;
170+
}
171+
159172
ds = [SkyEnterpriseProjectDataSource alloc]; // keep gcc happy
160-
ds = [ds initWithContext:[self context] enterpriseId:[self globalID]];
173+
ds = [ds initWithContext:[self context]
174+
enterpriseId:[self globalID]];
161175
return [ds autorelease];
162176
}
163177

164178
- (EODataSource *)allProjectsDataSource {
165179
SkyEnterpriseAllProjectsDataSource *ds;
166180

181+
if (self->globalID == nil) {
182+
[self logWithFormat:
183+
@"WARNING: no globalID for allProjects datasource"];
184+
return nil;
185+
}
186+
167187
ds = [SkyEnterpriseAllProjectsDataSource alloc]; // keep gcc happy
168-
ds = [ds initWithContext:[self context] enterpriseId:[self globalID]];
188+
ds = [ds initWithContext:[self context]
189+
enterpriseId:[self globalID]];
169190
return [ds autorelease];
170191
}
171192

DocumentAPI/OGoContacts/SkyPersonDocument.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,15 @@ - (EODataSource *)enterpriseDataSource {
186186
- (EODataSource *)projectDataSource {
187187
SkyPersonProjectDataSource *ds;
188188

189-
ds = [[SkyPersonProjectDataSource alloc] initWithContext:[self context]
190-
personId:[self globalID]];
189+
if (self->globalID == nil) {
190+
[self logWithFormat:
191+
@"WARNING: no globalID for project datasource"];
192+
return nil;
193+
}
194+
195+
ds = [[SkyPersonProjectDataSource alloc]
196+
initWithContext:[self context]
197+
personId:[self globalID]];
191198
return [ds autorelease];
192199
}
193200

WebUI/Contact/EnterprisesUI/SkyEnterpriseViewer.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,15 @@ - (BOOL)prepareForActivationCommand:(NSString *)_command
338338
id ctx;
339339

340340
if ([obj isKindOfClass:[EOGlobalID class]]) {
341+
EOGlobalID *gid = obj;
341342
obj = [[self runCommand:@"enterprise::get-by-globalid",
342-
@"gid", obj, nil] lastObject];
343+
@"gid", gid, nil] lastObject];
344+
if (obj == nil) {
345+
[self errorWithFormat:
346+
@"could not fetch enterprise for gid %@"
347+
@" (archived?)", gid];
348+
return NO;
349+
}
343350
}
344351
ctx = [self commandContext];
345352
obj = [[SkyEnterpriseDocument alloc] initWithEO:obj context:ctx];

WebUI/Contact/PersonsUI/SkyPersonViewer.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,15 @@ - (BOOL)prepareForActivationCommand:(NSString *)_command
276276
id ctx;
277277

278278
if ([obj isKindOfClass:[EOKeyGlobalID class]]) {
279+
EOGlobalID *gid = obj;
279280
obj = [[self runCommand:@"person::get-by-globalID",
280-
@"gid", obj, nil] lastObject];
281+
@"gid", gid, nil] lastObject];
282+
if (obj == nil) {
283+
[self errorWithFormat:
284+
@"could not fetch person for gid %@"
285+
@" (archived?)", gid];
286+
return NO;
287+
}
281288
}
282289
else {
283290
// should be an eo (activated by LSWViewAction/viewPerson)

0 commit comments

Comments
 (0)