From b5d070a6132fd789355b720fec910f1a2c5727a8 Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 10:52:25 +0000 Subject: [PATCH] fix(cli): Ignore SIGPIPE to prevent crashes on broken pipes --- Sources/CLI/main/AppleDocs.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/CLI/main/AppleDocs.swift b/Sources/CLI/main/AppleDocs.swift index 99008ca..bde1d3b 100644 --- a/Sources/CLI/main/AppleDocs.swift +++ b/Sources/CLI/main/AppleDocs.swift @@ -1,6 +1,14 @@ import ArgumentParser import Logging +#if canImport(Darwin) + import Darwin +#elseif canImport(Glibc) + import Glibc +#elseif canImport(Musl) + import Musl +#endif + @main enum AppleDocs { private static let logger = Logger(label: "com.techprimate.apple-docs") @@ -9,6 +17,11 @@ enum AppleDocs { static func main() async { let telemetry = Dependencies.shared.telemetry telemetry.start() + // Ignore SIGPIPE so writing to a closed pipe (e.g. `apple-docs ... | head`) + // fails with EPIPE instead of terminating the process. + // Must stay after `telemetry.start()`: the crash handler installs its own + // SIGPIPE handler during start, which would otherwise replace SIG_IGN. + signal(SIGPIPE, SIG_IGN) var loggingConfigured = false do {