Skip to content

Provide an environment flag to disable error backtrace capturing. #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions Sources/Testing/SourceAttribution/Backtrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,25 @@ extension Backtrace {
/// This value is named oddly so that it shows up clearly in symbolicated
/// backtraces.
private static let __SWIFT_TESTING_IS_CAPTURING_A_BACKTRACE_FOR_A_THROWN_ERROR__: Void = {
_ = isFoundationCaptureEnabled

_oldWillThrowHandler.withLock { oldWillThrowHandler in
oldWillThrowHandler = swt_setWillThrowHandler { errorAddress in
let backtrace = Backtrace.current()
_willThrow(errorAddress, from: backtrace)
}
#if SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") != false {
_ = isFoundationCaptureEnabled
}
if #available(_typedThrowsAPI, *) {
_oldWillThrowTypedHandler.withLock { oldWillThrowTypedHandler in
oldWillThrowTypedHandler = swt_setWillThrowTypedHandler { errorAddress, errorType, errorConformance in
#endif

if Environment.flag(named: "SWT_SWIFT_ERROR_BACKTRACING_ENABLED") != false {
_oldWillThrowHandler.withLock { oldWillThrowHandler in
oldWillThrowHandler = swt_setWillThrowHandler { errorAddress in
let backtrace = Backtrace.current()
_willThrowTyped(errorAddress, errorType, errorConformance, from: backtrace)
_willThrow(errorAddress, from: backtrace)
}
}
if #available(_typedThrowsAPI, *) {
_oldWillThrowTypedHandler.withLock { oldWillThrowTypedHandler in
oldWillThrowTypedHandler = swt_setWillThrowTypedHandler { errorAddress, errorType, errorConformance in
let backtrace = Backtrace.current()
_willThrowTyped(errorAddress, errorType, errorConformance, from: backtrace)
}
}
}
}
Expand Down