Delay Sentry initialization until after we parse the CLI arguments (#1085)

This commit is contained in:
Nikolay Edigaryev
2025-05-30 17:24:19 +04:00
committed by GitHub
parent 71159373e5
commit 8539b8faae
+24 -23
View File
@@ -31,6 +31,29 @@ struct Root: AsyncParsableCommand {
]) ])
public static func main() async throws { public static func main() async throws {
// Add commands that are only available on specific macOS versions
if #available(macOS 14, *) {
configuration.subcommands.append(Suspend.self)
}
// Ensure the default SIGINT handled is disabled,
// otherwise there's a race between two handlers
signal(SIGINT, SIG_IGN);
// Handle cancellation by Ctrl+C ourselves
let task = withUnsafeCurrentTask { $0 }!
let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT)
sigintSrc.setEventHandler {
task.cancel()
}
sigintSrc.activate()
// Set line-buffered output for stdout
setlinebuf(stdout)
do {
// Parse command
var command = try parseAsRoot()
// Initialize Sentry // Initialize Sentry
if let dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"] { if let dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"] {
SentrySDK.start { options in SentrySDK.start { options in
@@ -64,29 +87,6 @@ struct Root: AsyncParsableCommand {
} }
} }
// Add commands that are only available on specific macOS versions
if #available(macOS 14, *) {
configuration.subcommands.append(Suspend.self)
}
// Ensure the default SIGINT handled is disabled,
// otherwise there's a race between two handlers
signal(SIGINT, SIG_IGN);
// Handle cancellation by Ctrl+C ourselves
let task = withUnsafeCurrentTask { $0 }!
let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT)
sigintSrc.setEventHandler {
task.cancel()
}
sigintSrc.activate()
// Set line-buffered output for stdout
setlinebuf(stdout)
// Parse and run command
do {
var command = try parseAsRoot()
// Run garbage-collection before each command (shouldn't take too long) // Run garbage-collection before each command (shouldn't take too long)
if type(of: command) != type(of: Pull()) && type(of: command) != type(of: Clone()){ if type(of: command) != type(of: Pull()) && type(of: command) != type(of: Clone()){
do { do {
@@ -96,6 +96,7 @@ struct Root: AsyncParsableCommand {
} }
} }
// Run command
if var asyncCommand = command as? AsyncParsableCommand { if var asyncCommand = command as? AsyncParsableCommand {
try await asyncCommand.run() try await asyncCommand.run()
} else { } else {