Skip to content
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

Abort and StackTrace improvements #2400

Merged
merged 4 commits into from Jun 15, 2020
Merged

Abort and StackTrace improvements #2400

merged 4 commits into from Jun 15, 2020

Conversation

tanner0101
Copy link
Member

@tanner0101 tanner0101 commented Jun 15, 2020

Abort now conforms to DebuggableError (#2400).

Abort now exposes source, reason, identifier, and stackTrace via the DebuggableError protocol.

⚠️ Abort.source is now an optional as required by DebuggableError.

Abort now captures StackTrace by default.

func foo() throws {
    try bar()
}
func bar() throws {
    try baz()
}
func baz() throws {
    throw Abort(.internalServerError, reason: "Oops")
}
do {
    try foo()
} catch let error as DebuggableError {
    XCTAssertContains(error.stackTrace?.frames[0].function, "baz")
    XCTAssertContains(error.stackTrace?.frames[1].function, "bar")
    XCTAssertContains(error.stackTrace?.frames[2].function, "foo")
}

To avoid capturing a stack trace, pass nil:

Abort(.internalServerError, reason: "Oops", stackTrace: nil)

To disable stack traces globally, use:

StackTrace.isCaptureEnabled = false

Improved StackTrace.capture on Linux (#2400).

StackTrace.capture on Linux now utilizes libbacktrace to provide symbol names.

0 VaporTests baz #1 () throws -> () in VaporTests.ErrorTests.testAbortDebuggable() throws -> ()
1 VaporTests bar #1 () throws -> () in VaporTests.ErrorTests.testAbortDebuggable() throws -> ()
2 VaporTests foo #1 () throws -> () in VaporTests.ErrorTests.testAbortDebuggable() throws -> ()
3 VaporTests VaporTests.ErrorTests.testAbortDebuggable() throws -> ()
...

StackFrame.capture now accepts an optional skip parameter. Use this to exclude any extraneous stack frames from the captured result.

// Captures stack trace, excluding this init call.
init(stackTrace: StackTrace? = .capture(skip: 1)) {
    ...
}

@tanner0101 tanner0101 added enhancement New feature or request semver-minor Contains new API labels Jun 15, 2020
@tanner0101 tanner0101 added this to Awaiting Review in Vapor 4 via automation Jun 15, 2020
@tanner0101 tanner0101 changed the title Conform Abort to DebuggableError Error and StackTrace improvements Jun 15, 2020
@tanner0101 tanner0101 changed the title Error and StackTrace improvements Abort and StackTrace improvements Jun 15, 2020
@tanner0101 tanner0101 marked this pull request as ready for review June 15, 2020 22:53
@tanner0101 tanner0101 merged commit 2bfe714 into master Jun 15, 2020
Vapor 4 automation moved this from Awaiting Review to Done Jun 15, 2020
@tanner0101 tanner0101 deleted the tn-abort-debuggable branch June 15, 2020 22:58
@tanner0101
Copy link
Member Author

These changes are now available in 4.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-minor Contains new API
Projects
Vapor 4
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant