Add PrototypeKitError and optional onError handlers#13
Merged
Conversation
Lets consuming apps react to setup failures instead of only reading the log
(the library still degrades gracefully and logs as before).
- New public `PrototypeKitError` (LocalizedError): `.modelLoadFailed(url:underlying:)`
and `.soundClassificationFailed(underlying:)`.
- Optional `onError:` closure (defaults to nil, so source-compatible) on the entry
points that can fail at setup:
- ImageClassifierView, HandPoseClassifierView, classifyActivity(...) — fires on
model-load failure (on appear).
- recognizeSounds(...) — fires on a failed start (bad custom model) and on session
errors (denied mic access, audio interruptions), sourced from a new long-lived
`errors` relay on SystemAudioClassifier.
- Transient per-frame Vision errors stay log-only by design (they would spam a callback).
- Tests for the error descriptions and that the onError-accepting inits don't crash.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wwQvH5kuGmjQ9nW3gJ6zD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Gives consuming apps a way to react to failures. Today PrototypeKit degrades gracefully and logs errors via
os.Logger, but the app has no signal — a bad model URL just shows a camera feed with no predictions. This adds an opt-in error channel so an app can show a message, offer a retry, etc.API
PrototypeKitError(LocalizedError):.modelLoadFailed(url:underlying:).soundClassificationFailed(underlying:)onError: ((PrototypeKitError) -> Void)?(defaults tonil) on the entry points that can fail at setup:ImageClassifierView,HandPoseClassifierView,classifyActivity(...)— fires on model-load failure (delivered on appear, on the main thread).recognizeSounds(...)— fires on a failed start (bad custom model) and on session errors (denied microphone access, audio-session interruptions), sourced from a new long-livederrorsrelay onSystemAudioClassifier.Deliberate scope
onErroris a trailing optional defaulting tonil; existing call sites are untouched, and errors are still logged exactly as before.onErrorhook is reserved for "this feature won't work" conditions.LiveFaceDetectorView, etc.) have no setup-failure mode (no model to load), so they don't gain anonError— that's intentional, not an omission.Tests
PrototypeKitErrordescriptions, and that theonError-accepting initializers construct without crashing. (The callback firing on appear is a SwiftUI lifecycle behavior best verified in-app / UI tests.)Authored without a local Swift toolchain, so CI here is the first machine build.
🤖 Generated with Claude Code
Generated by Claude Code