-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Avoid terminating when a precondition is not met in HTTPServerPipelineHandler #2550
Conversation
@swift-server-bot add to allowlist |
var file: String | ||
var line: Int | ||
|
||
init(base: Base, file: String, line: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, and the various var
s, may as well be private
.
var description: String { | ||
switch self { | ||
case .preconditionViolated(let message): | ||
return message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a "precondition violated"
to this description as well
44385ac
to
d6d5575
Compare
d6d5575
to
828f362
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, just one very minor nit.
} | ||
|
||
/// Calls assert if and only if `self.failOnPreconditions` is true. This allows us to avoid terminating the program in tests | ||
private func checkPrecondition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a minor nit here, but let's replace the word precondition
in these two functions with assertion
. They only fail in debug mode so they behave like assertions, not preconditions, and it'll be a little less confusing at the call site I think.
We can keep the word precondition
in the error, that works well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, this LGTM. Nice one!
Motivation:
HTTPServerPipelineHandler
has a few preconditionFailures in its state machine. This isn’t really ideal, as while these are important invariants, it is fairly easy for users to accidentally break them.Modifications:
We continue to crash (by calling assertionFailure) when in debug mode, to make it obvious to users that they have violated an invariant
However, an internal flag allows us to disable this behaviour for testing
Result:
Making an illegal state change in
HTTPServerPipelineHandler
will no longer crash