Repository navigation
Turn AVFAudio exceptions in mic start into errors, and say so when a call can't be recorded - #73
Open
ddobrinskiy wants to merge 1 commit into
Open
ddobrinskiy wants to merge 1 commit into
ddobrinskiy wants to merge 1 commit into
Conversation
…call can't be recorded AVFAudio reports misuse (a second installTap, a tap format that doesn't match the input) by raising an Objective-C NSException. Swift cannot catch it. Raised from MicRecorder.start, it unwound through RecordingSession.start without running the catch that stops the system tap, and: - from the auto-record timer it killed that timer for the rest of the run, so no call was recorded automatically until amanu was restarted, while the system tap kept recording with the menu showing idle (2026-11-16: a 74 h system-only recording); - from `amanu record start` it terminated the app. A small Objective-C target (AmanuObjC) wraps the AVAudioEngine calls in @try/@catch and returns an NSError, so the existing failure path runs: the tap is stopped, the folder is removed and the start-failed banner is shown. The banner now says that the call is not being recorded and what to try, without the system's error text (that stays in the log). Tested against real AVFAudio exceptions (double tap, format mismatch); without the catcher the test process aborts. Also exercised in the real app with the exception injected into installTap: the original build aborts, this build logs the failure, shows the banner and keeps running.
Author
|
@gsamat could you review this when you have a moment? It fixes #72. Two things worth a look: the new |
This branch has not been deployed
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.
Fixes #72.
AVFAudio reports misuse by raising an Objective-C exception, which Swift cannot catch. When the mic start raised, the exception skipped
RecordingSession.start'scatch, so the system tap kept recording, and it killed the auto-record timer (or aborted the app when the start came fromamanu record start). Details and a one-file reproduction are in the issue.What changes
AmanuObjC: a small Objective-C target withAmanuObjCExceptionCatcher.catching(_:), which runs a block inside@try/@catchand returns the exception as anNSError(name and reason kept). SwiftPM needs a separate target for Objective-C; it adds no dependency.MicRecorder:engine.connect,prepare()/start()and bothinstallTapcalls in the mic start go throughMicRecorder.guarded, andinstallVoiceTapnow throws. A raise then takes the path that already exists:attachWithFallbacks, thenStartFailure.microphone, which stops the system tap and removes the folder. Auto-record keeps running.StartFailure.bannerBodyreplaces the raw error text in the start-failed banner with one sentence saying the call is not being recorded and what to try (English and Russian, like the rest of the banners). The system's error text stays in the log.Tests
MicExceptionGuardTests: an exception raised from the body becomes a thrown error with its reason (no hardware needed); a body that does not raise runs untouched; a real secondinstallTapand a real format mismatch become thrown errors (these two are cancelled when the machine has no audio input).RecordingSessionTests: an Objective-C exception inside the mic start ends asStartFailure.microphone, with the system tap stopped and no folder left. No hardware needed.StartFailureBannerTests: the banner says the call is not being recorded and does not contain the raw error.NSException.swift test: 773 tests pass.landing/tests/check.pypasses.Tests/scriptshas 3 errors that are identical on an untouchedorigin/masteron my machine (the compatibility tests cannot link against the Command Line Tools SDK here).installTap(a test-only dylib on an ad-hoc-signed build): 0.6.5 aborts onamanu record start; with this change the failure is logged, the banner appears, the app keeps running, and the folder is removed. A normal recording started and stopped withamanu recordstill works:mic.cafandsystem.cafwhile it runs, thenaudio.m4aandmeta.json.Not changed
Setup/Permissions.swiftalso callsAVAudioEngine.connect/start; it is not on the recording path and I left it alone.