fix: comprehensive codebase hardening — crashes, silent failures, performance, and security
Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,9 @@ struct DateRangePicker: View {
|
||||
|
||||
var days: [Date?] = []
|
||||
let startOfMonth = monthInterval.start
|
||||
let endOfMonth = calendar.date(byAdding: .day, value: -1, to: monthInterval.end)!
|
||||
guard let endOfMonth = calendar.date(byAdding: .day, value: -1, to: monthInterval.end) else {
|
||||
return []
|
||||
}
|
||||
|
||||
// Get the first day of the week containing the first day of the month
|
||||
var currentDate = monthFirstWeek.start
|
||||
@@ -57,7 +59,10 @@ struct DateRangePicker: View {
|
||||
} else {
|
||||
break
|
||||
}
|
||||
currentDate = calendar.date(byAdding: .day, value: 1, to: currentDate)!
|
||||
guard let nextDate = calendar.date(byAdding: .day, value: 1, to: currentDate) else {
|
||||
break
|
||||
}
|
||||
currentDate = nextDate
|
||||
}
|
||||
|
||||
return days
|
||||
|
||||
@@ -249,8 +249,13 @@ struct GamePickerStep: View {
|
||||
private func loadSummaryGames() async {
|
||||
var games: [RichGame] = []
|
||||
for teamId in selectedTeamIds {
|
||||
if let teamGames = try? await AppDataProvider.shared.gamesForTeam(teamId: teamId) {
|
||||
do {
|
||||
let teamGames = try await AppDataProvider.shared.gamesForTeam(teamId: teamId)
|
||||
games.append(contentsOf: teamGames)
|
||||
} catch {
|
||||
#if DEBUG
|
||||
print("⚠️ [GamePickerStep] Failed to load summary games for team \(teamId): \(error)")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
await MainActor.run {
|
||||
@@ -635,9 +640,14 @@ private struct GamesPickerSheet: View {
|
||||
private func loadGames() async {
|
||||
var allGames: [RichGame] = []
|
||||
for teamId in selectedTeamIds {
|
||||
if let teamGames = try? await AppDataProvider.shared.gamesForTeam(teamId: teamId) {
|
||||
do {
|
||||
let teamGames = try await AppDataProvider.shared.gamesForTeam(teamId: teamId)
|
||||
let futureGames = teamGames.filter { $0.game.dateTime > Date() }
|
||||
allGames.append(contentsOf: futureGames)
|
||||
} catch {
|
||||
#if DEBUG
|
||||
print("⚠️ [GamePickerStep] Failed to load games for team \(teamId): \(error)")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ struct MustStopsStep: View {
|
||||
|
||||
if !mustStopLocations.isEmpty {
|
||||
VStack(spacing: Theme.Spacing.xs) {
|
||||
ForEach(mustStopLocations, id: \.name) { location in
|
||||
ForEach(Array(mustStopLocations.enumerated()), id: \.offset) { _, location in
|
||||
HStack {
|
||||
Image(systemName: "mappin.circle.fill")
|
||||
.foregroundStyle(Theme.warmOrange)
|
||||
|
||||
@@ -126,9 +126,14 @@ struct ReviewStep: View {
|
||||
}
|
||||
}
|
||||
|
||||
private static let mediumDateFormatter: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.dateStyle = .medium
|
||||
return f
|
||||
}()
|
||||
|
||||
private var dateRangeText: String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
let formatter = Self.mediumDateFormatter
|
||||
return "\(formatter.string(from: startDate)) - \(formatter.string(from: endDate))"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ struct TeamPickerStep: View {
|
||||
|
||||
private var selectedTeam: Team? {
|
||||
guard let teamId = selectedTeamId else { return nil }
|
||||
return AppDataProvider.shared.teams.first { $0.id == teamId }
|
||||
return AppDataProvider.shared.team(for: teamId)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -18,7 +18,7 @@ struct TeamFirstWizardStep: View {
|
||||
|
||||
private var selectedTeams: [Team] {
|
||||
selectedTeamIds.compactMap { teamId in
|
||||
AppDataProvider.shared.teams.first { $0.id == teamId }
|
||||
AppDataProvider.shared.team(for: teamId)
|
||||
}.sorted { $0.fullName < $1.fullName }
|
||||
}
|
||||
|
||||
|
||||
@@ -193,8 +193,8 @@ struct TripWizardView: View {
|
||||
let preferences = buildPreferences()
|
||||
|
||||
// Build dictionaries from arrays
|
||||
let teamsById = Dictionary(uniqueKeysWithValues: AppDataProvider.shared.teams.map { ($0.id, $0) })
|
||||
let stadiumsById = Dictionary(uniqueKeysWithValues: AppDataProvider.shared.stadiums.map { ($0.id, $0) })
|
||||
let teamsById = Dictionary(AppDataProvider.shared.teams.map { ($0.id, $0) }, uniquingKeysWith: { _, last in last })
|
||||
let stadiumsById = Dictionary(AppDataProvider.shared.stadiums.map { ($0.id, $0) }, uniquingKeysWith: { _, last in last })
|
||||
|
||||
// For gameFirst mode, use the UI-selected date range (set by GamePickerStep)
|
||||
// The date range is a 7-day span centered on the selected game(s)
|
||||
|
||||
Reference in New Issue
Block a user