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:
@@ -7,6 +7,9 @@
|
||||
|
||||
import Foundation
|
||||
import CloudKit
|
||||
import os
|
||||
|
||||
private let logger = Logger(subsystem: "com.88oakapps.SportsTime", category: "CKModels")
|
||||
|
||||
// MARK: - Record Type Constants
|
||||
|
||||
@@ -201,13 +204,18 @@ nonisolated struct CKStadium {
|
||||
let sport = Sport(rawValue: sportRaw.uppercased()) ?? .mlb
|
||||
let timezoneIdentifier = (record[CKStadium.timezoneIdentifierKey] as? String)?.ckTrimmed
|
||||
|
||||
guard let location else {
|
||||
logger.warning("Missing location coordinates for stadium '\(id)' — skipping")
|
||||
return nil
|
||||
}
|
||||
|
||||
return Stadium(
|
||||
id: id,
|
||||
name: name,
|
||||
city: city,
|
||||
state: state,
|
||||
latitude: location?.coordinate.latitude ?? 0,
|
||||
longitude: location?.coordinate.longitude ?? 0,
|
||||
latitude: location.coordinate.latitude,
|
||||
longitude: location.coordinate.longitude,
|
||||
capacity: capacity,
|
||||
sport: sport,
|
||||
yearOpened: record[CKStadium.yearOpenedKey] as? Int,
|
||||
@@ -622,8 +630,11 @@ nonisolated struct CKTripPoll {
|
||||
record[CKTripPoll.ownerIdKey] = poll.ownerId
|
||||
record[CKTripPoll.shareCodeKey] = poll.shareCode
|
||||
// Encode trips as JSON data
|
||||
if let tripsData = try? JSONEncoder().encode(poll.tripSnapshots) {
|
||||
do {
|
||||
let tripsData = try JSONEncoder().encode(poll.tripSnapshots)
|
||||
record[CKTripPoll.tripSnapshotsKey] = tripsData
|
||||
} catch {
|
||||
logger.error("Failed to encode tripSnapshots for poll \(poll.id.uuidString): \(error.localizedDescription)")
|
||||
}
|
||||
record[CKTripPoll.tripVersionsKey] = poll.tripVersions
|
||||
record[CKTripPoll.createdAtKey] = poll.createdAt
|
||||
@@ -730,7 +741,7 @@ nonisolated struct CKPollVote {
|
||||
let record = CKRecord(recordType: CKRecordType.pollVote, recordID: CKRecord.ID(recordName: vote.id.uuidString))
|
||||
record[CKPollVote.voteIdKey] = vote.id.uuidString
|
||||
record[CKPollVote.pollIdKey] = vote.pollId.uuidString
|
||||
record[CKPollVote.voterIdKey] = vote.odg
|
||||
record[CKPollVote.voterIdKey] = vote.voterId
|
||||
record[CKPollVote.rankingsKey] = vote.rankings
|
||||
record[CKPollVote.votedAtKey] = vote.votedAt
|
||||
record[CKPollVote.modifiedAtKey] = vote.modifiedAt
|
||||
@@ -751,7 +762,7 @@ nonisolated struct CKPollVote {
|
||||
return PollVote(
|
||||
id: voteId,
|
||||
pollId: pollId,
|
||||
odg: voterId,
|
||||
voterId: voterId,
|
||||
rankings: rankings,
|
||||
votedAt: votedAt,
|
||||
modifiedAt: modifiedAt
|
||||
|
||||
Reference in New Issue
Block a user