Surface pedal/board edit failures as a UI alert

Adding a second stereo (widener) pedal — e.g. two Granulators in a row —
threw ShoeGazeError.stereoWidthExceeded, which was only printed to the
console. Route the addPedal / routing / addBoard catch blocks to an alert
with player-facing wording (stereo-width / merge cases mapped to plain text;
others fall back to the error's LocalizedError description). Alert lives on
its own presentation anchor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 15:30:31 -07:00
parent bc7157b7ee
commit bc6e6286df
@@ -118,6 +118,16 @@ public struct ShoeGazeBuilderView: View {
@State private var pendingSwitchEntry: RigEntry?
@State private var showSwitchSaveDialog: Bool = false
/// A failed edit (add pedal / routing / board) to surface as an alert. `nil` = no alert.
@State private var actionError: ActionError?
/// A user-facing failure message for the action-error alert.
private struct ActionError: Identifiable {
let id: UUID = UUID()
let title: String
let message: String
}
/// Archive export state. Cross-platform: backs the sidebar's Export Archive and the
/// "Save & Clear" flow is separate (it saves to the library, not a file).
@State private var showExporter: Bool = false
@@ -193,6 +203,7 @@ public struct ShoeGazeBuilderView: View {
.background(boardsSheetAnchor)
.background(rigExportAnchor)
.background(rigImportAnchor)
.background(actionErrorAnchor)
.rigNamePrompt($namePrompt)
.confirmationDialog(
"Erase all rigs?",
@@ -374,6 +385,43 @@ public struct ShoeGazeBuilderView: View {
}
}
/// Hosts the action-failure alert on its own node (one presentation per node).
private var actionErrorAnchor: some View {
Color.clear
.alert(
actionError?.title ?? "",
isPresented: Binding(
get: { actionError != nil },
set: { presented in if !presented { actionError = nil } }
),
presenting: actionError
) { _ in
Button("OK", role: .cancel) { }
} message: { error in
Text(error.message)
}
}
/// Surfaces a failed edit as an alert (and logs it). Maps the common stereo-width / merge errors
/// to player-facing wording (no API names); otherwise uses the error's `LocalizedError` text.
private func reportError(_ title: String, _ error: Error) {
actionError = ActionError(title: title, message: friendlyMessage(for: error))
}
private func friendlyMessage(for error: Error) -> String {
switch error as? ShoeGazeError {
case .stereoWidthExceeded, .cannotSplitStereoChain:
return "This board is already in stereo. Add a “Merge to Mono” before another stereo "
+ "(widening) pedal such as Chorus, Rotary, or a Granulator."
case .cannotMergeMonoChain:
return "This board is already mono — there’s no stereo signal to merge."
case .cannotUnzipMonoChain:
return "This board is mono — there’s no stereo signal to split into left/right lanes."
default:
return (error as? LocalizedError)?.errorDescription ?? error.localizedDescription
}
}
#if !os(macOS)
/// Hosts the recording-folder importer on its own node.
private var recordingFolderImportAnchor: some View {
@@ -472,6 +520,7 @@ public struct ShoeGazeBuilderView: View {
}
} catch {
print("[ShoeGazeBuilderView] routing \(action) failed: \(error)")
reportError("Couldn’t add routing", error)
}
}
@@ -516,6 +565,7 @@ public struct ShoeGazeBuilderView: View {
autosave()
} catch {
print("[ShoeGazeBuilderView] appendPedal failed: \(error)")
reportError("Couldn’t add \(type)", error)
}
}
@@ -530,6 +580,7 @@ public struct ShoeGazeBuilderView: View {
} catch {
if let board: PedalBoard = created { shoeGaze.removeBoard(board) }
print("[ShoeGazeBuilderView] addBoard failed: \(error)")
reportError("Couldn’t add board", error)
}
}