You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These work because the strings are all constants and known to parse. But:
A typo in any one of them crashes the app with Fatal error: Unexpectedly found nil.
The pattern makes it harder to grep for API paths — they are scattered across the file as interpolated strings.
If NetworkManager.baseURL ever becomes dynamic (different env / staging), the compiler will not help catch misuses.
Proposed fix
Add a small helper on URL:
extensionURL{staticfunc api(path:String)->URL{guardlet url =URL(string:"\(NetworkManager.baseURL)\(path)")else{preconditionFailure("Invalid API URL: \(NetworkManager.baseURL)\(path)")}return url
}}
Then replace every force-unwrap:
// Before
leturl=URL(string:"\(NetworkManager.baseURL)/auth/login")!
// After
leturl=URL.api(path:"/auth/login")
The preconditionFailure still crashes on an invalid URL (the behavior is identical to force-unwrap) but it gives a descriptive error instead of Fatal error: Unexpectedly found nil, and centralizes the construction so a future dynamic base URL has one place to change.
Other files to check
The review only called out AuthenticationManager.swift, but the same pattern likely exists in:
NetworkManager.swift
FavoritesManager.swift
RepertoireManager.swift
RecordingDetailViewModel.swift — has one at URL(string: "\(NetworkManager.baseURL)/recordings/\(recordingId)")
Grep for URL(string:.*baseURL and fix them all in one pass.
Not in scope
Changing how NetworkManager.baseURL is defined or configured.
Rewriting the request methods themselves.
Context links
apps/Shared/Auth/AuthenticationManager.swift — the eight lines listed above
apps/Shared/Support/NetworkManager.swift — probably has more of the same pattern
Context
From
doc/architecture-review-2026-04.md— P4 #5.apps/Shared/Auth/AuthenticationManager.swifthas eight force-unwrapped URL constructions. The review lists the specific lines:Each is the pattern:
These work because the strings are all constants and known to parse. But:
Fatal error: Unexpectedly found nil.NetworkManager.baseURLever becomes dynamic (different env / staging), the compiler will not help catch misuses.Proposed fix
Add a small helper on
URL:Then replace every force-unwrap:
The
preconditionFailurestill crashes on an invalid URL (the behavior is identical to force-unwrap) but it gives a descriptive error instead ofFatal error: Unexpectedly found nil, and centralizes the construction so a future dynamic base URL has one place to change.Other files to check
The review only called out
AuthenticationManager.swift, but the same pattern likely exists in:NetworkManager.swiftFavoritesManager.swiftRepertoireManager.swiftRecordingDetailViewModel.swift— has one atURL(string: "\(NetworkManager.baseURL)/recordings/\(recordingId)")Grep for
URL(string:.*baseURLand fix them all in one pass.Not in scope
NetworkManager.baseURLis defined or configured.Context links
apps/Shared/Auth/AuthenticationManager.swift— the eight lines listed aboveapps/Shared/Support/NetworkManager.swift— probably has more of the same patterndoc/architecture-review-2026-04.md(P4 Provide a filer for releases #5)🤖 Generated with Claude Code