SmartFoldersDemo: Surface framework exceptions by removing silent fallbacks

Catching exceptions and substituting defaults masked failures in predicate parsing, evaluation, array controller filtering, and predicate editor round-trips, and replaced unreadable stored libraries with sample data behind a console warning.

- Library: Parse stored smart folder predicates, evaluate predicates, and
  load stored libraries without exception handlers; return smart folder
  counts directly.

- PeopleViewController: Set array controller filter predicates without
  falling back to nil.

- SmartFolderEditorController: Set and read predicate editor values without
  exception handlers or fallback predicates.

- AppController: Document the omission of exception handling and sample-data
  recovery for unreadable stored libraries.
This commit is contained in:
David Richardson committed 2026-11-16 16:11:39 -06:00
1 parent 6da20783fd
commit 3702d682eb
4 files changed
+22 -76

No files matched your search

@@ -17,6 +17,11 @@
*
* Data (people, groups, smart folders) is persisted in CPUserDefaults.
* Use File ▸ Reset Library… to return to the deterministic sample data.
*
* The application catches no exception. It tests the frameworks, so a
* framework failure must show and must not fall back to a default. If the
* stored library cannot load, launch stops with the exception; delete the
* site's local storage to return to the sample data.
*/
@import <Foundation/Foundation.j>
+13 -47
View File
@@ -152,20 +152,9 @@ var LibraryDefaultsKey = @"SmartFoldersDemo.Library.v1",
- (id)initWithDictionary:(CPDictionary)aDictionary
{
var format = [aDictionary objectForKey:@"predicate"],
aPredicate = nil;
aPredicate = format ? [CPPredicate predicateWithFormat:format] : [CPPredicate predicateWithValue:YES];
try
{
if (format)
aPredicate = [CPPredicate predicateWithFormat:format];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: could not parse stored predicate '" + format + "': " + e);
}
return [self initWithName:[aDictionary objectForKey:@"name"] || @"Smart Folder"
predicate:aPredicate || [CPPredicate predicateWithValue:YES]];
return [self initWithName:[aDictionary objectForKey:@"name"] || @"Smart Folder" predicate:aPredicate];
}
- (CPDictionary)dictionaryRepresentation
@@ -361,15 +350,7 @@ var LibraryDefaultsKey = @"SmartFoldersDemo.Library.v1",
if (!aPredicate)
return _people;
try
{
return [_people filteredArrayUsingPredicate:aPredicate];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: predicate evaluation failed: " + e);
return nil;
}
return [_people filteredArrayUsingPredicate:aPredicate];
}
- (int)countForItem:(id)anItem
@@ -383,8 +364,7 @@ var LibraryDefaultsKey = @"SmartFoldersDemo.Library.v1",
if (!predicate)
return [base count];
var matches = [self peopleMatchingPredicate:predicate];
return matches ? [matches count] : CPNotFound;
return [[self peopleMatchingPredicate:predicate] count];
}
// ---------------------------------------------------------------- People mutation
@@ -659,32 +639,18 @@ var LibraryDefaultsKey = @"SmartFoldersDemo.Library.v1",
if (!dictionary || ![dictionary isKindOfClass:[CPDictionary class]])
return NO;
try
{
var people = [dictionary objectForKey:@"people"] || [],
groups = [dictionary objectForKey:@"groups"] || [],
folders = [dictionary objectForKey:@"smartFolders"] || [];
var people = [dictionary objectForKey:@"people"] || [],
groups = [dictionary objectForKey:@"groups"] || [],
folders = [dictionary objectForKey:@"smartFolders"] || [];
for (var i = 0; i < people.length; i++)
[self _insertPerson:[[Person alloc] initWithDictionary:people[i]]];
for (var i = 0; i < people.length; i++)
[self _insertPerson:[[Person alloc] initWithDictionary:people[i]]];
for (var i = 0; i < groups.length; i++)
[[_groupsSection children] addObject:[[LibraryGroup alloc] initWithDictionary:groups[i]]];
for (var i = 0; i < groups.length; i++)
[[_groupsSection children] addObject:[[LibraryGroup alloc] initWithDictionary:groups[i]]];
for (var i = 0; i < folders.length; i++)
[[_smartFoldersSection children] addObject:[[SmartFolder alloc] initWithDictionary:folders[i]]];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: stored library is unreadable, using sample data. " + e);
_people = [];
_peopleByUID = {};
[[_groupsSection children] removeAllObjects];
[[_smartFoldersSection children] removeAllObjects];
return NO;
}
for (var i = 0; i < folders.length; i++)
[[_smartFoldersSection children] addObject:[[SmartFolder alloc] initWithDictionary:folders[i]]];
return [_people count] > 0;
}
@@ -249,16 +249,7 @@
_contentTitle = aTitle || @"";
try
{
[_arrayController setFilterPredicate:aPredicate];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: filter predicate failed: " + e);
[_arrayController setFilterPredicate:nil];
}
[_arrayController setFilterPredicate:aPredicate];
[_arrayController setContent:[thePeople copy]];
[_arrayController setSelectedObjects:selected];
@@ -276,29 +276,13 @@ var EditorWidth = 680.0,
if (![aPredicate isKindOfClass:[CPCompoundPredicate class]])
aPredicate = [CPCompoundPredicate andPredicateWithSubpredicates:[aPredicate]];
try
{
[_predicateEditor setObjectValue:aPredicate];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: CPPredicateEditor could not represent " + [aPredicate predicateFormat] + ": " + e);
[_predicateEditor setObjectValue:[CPCompoundPredicate andPredicateWithSubpredicates:[[CPPredicate predicateWithFormat:@"lastName CONTAINS[cd] %@", @""]]]];
}
[_predicateEditor setObjectValue:aPredicate];
}
- (CPPredicate)_currentPredicate
{
try
{
[_predicateEditor reloadPredicate];
return [_predicateEditor predicate];
}
catch (e)
{
CPLog.warn("SmartFoldersDemo: could not build predicate: " + e);
return nil;
}
[_predicateEditor reloadPredicate];
return [_predicateEditor predicate];
}
- (void)closeSheet:(id)sender