Skip to content

bug: CLIHandler --debug may crash on exit if /usr/bin/log failed to launch #62

@fmasi

Description

@fmasi

CLIHandler --debug: defer { logProcess?.terminate() } may crash on exit if /usr/bin/log failed to launch. (Severity: nit.)

Root cause
In handleTranscribe(_:) (TranscriberApp/Services/CLIHandler.swift:64-78):

let proc = Process()
proc.executableURL = URL(fileURLWithPath: "/usr/bin/log")
try? proc.run()        // swallows launch error
logProcess = proc      // unconditional assignment
...
defer { logProcess?.terminate() }

If proc.run() throws, logProcess holds a never-launched Process. Process.terminate() on an unlaunched task raises an Objective-C NSInvalidArgumentException ("task not launched"), which Swift cannot catch → SIGABRT (exit 134) on exit, after transcription output was already written.

Impact
Narrow trigger — /usr/bin/log is standard on macOS, app is non-sandboxed. Fires only in hardened/sandboxed test harnesses, corrupted installs, or transient fork/exec failures. No data loss (crash is in the exit defer). Filed as nit.

Fix (smallest diff)
Guard the defer:

defer { if logProcess?.isRunning == true { logProcess?.terminate() } }

or only assign logProcess = proc inside a do { try proc.run(); logProcess = proc } catch { ... }.

Found by ultrareview of PR #46 (bug_001).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreview-followupTracked from a PR review (Copilot/Claude bot or human)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions