mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-28 05:14:25 +00:00
Add a location to each of 'NIOHTTP2Errors' (#247)
Motivation: Without knowing where an error was thrown it can be unnecessarily difficult to work out the reasons an application ended up in an error state. Modifications: - Add a 'file' string to each of the 'NIOHTTP2Errors' denoting the file and line where an error was created - Add static methods to create errors to 'NIOHTTP2Errors' defaulting file and line, this is unfortunately necessary as defaulting file and line in the `init` makes the defaulted and non-defaulted errors indistinguishable, and the compiler will pick the one with fewest defaulted values. - Add equatable conformance manually so as to ignore 'file' - Add backing storage to errors which no longer be stored in an existential container - Add 'CustomStringConvertible' conformance to the errors using backing storage so that the 'file' is actually visible when converting the error - Deprecate the old `init`s - Fix all deprecation warnings Result: - NIOHTTP2Errors carry a 'file' with them indicating where they were created
This commit is contained in:
1 parent
28d94c489d
commit
440d64d99a
33 files changed
+1598
-233
No files matched your search
@@ -228,15 +228,15 @@ struct ConnectionStreamState {
|
||||
/// Adjusts the stream state to reserve a client stream ID.
|
||||
mutating func reserveClientStreamID(_ streamID: HTTP2StreamID) throws {
|
||||
guard self.clientStreamCount < self.maxClientInitiatedStreams else {
|
||||
throw NIOHTTP2Errors.MaxStreamsViolation()
|
||||
throw NIOHTTP2Errors.maxStreamsViolation()
|
||||
}
|
||||
|
||||
guard streamID > self.lastClientStreamID else {
|
||||
throw NIOHTTP2Errors.StreamIDTooSmall()
|
||||
throw NIOHTTP2Errors.streamIDTooSmall()
|
||||
}
|
||||
|
||||
guard streamID.mayBeInitiatedBy(.client) else {
|
||||
throw NIOHTTP2Errors.InvalidStreamIDForPeer()
|
||||
throw NIOHTTP2Errors.invalidStreamIDForPeer()
|
||||
}
|
||||
|
||||
self.lastClientStreamID = streamID
|
||||
@@ -246,15 +246,15 @@ struct ConnectionStreamState {
|
||||
/// Adjusts the stream state to reserve a server stream ID.
|
||||
mutating func reserveServerStreamID(_ streamID: HTTP2StreamID) throws {
|
||||
guard self.serverStreamCount < self.maxServerInitiatedStreams else {
|
||||
throw NIOHTTP2Errors.MaxStreamsViolation()
|
||||
throw NIOHTTP2Errors.maxStreamsViolation()
|
||||
}
|
||||
|
||||
guard streamID > self.lastServerStreamID else {
|
||||
throw NIOHTTP2Errors.StreamIDTooSmall()
|
||||
throw NIOHTTP2Errors.streamIDTooSmall()
|
||||
}
|
||||
|
||||
guard streamID.mayBeInitiatedBy(.server) else {
|
||||
throw NIOHTTP2Errors.InvalidStreamIDForPeer()
|
||||
throw NIOHTTP2Errors.invalidStreamIDForPeer()
|
||||
}
|
||||
|
||||
self.lastServerStreamID = streamID
|
||||
@@ -310,13 +310,13 @@ struct ConnectionStreamState {
|
||||
case true where streamID > self.lastClientStreamID,
|
||||
false where streamID > self.lastServerStreamID:
|
||||
// The stream in question is idle.
|
||||
return .connectionError(underlyingError: NIOHTTP2Errors.NoSuchStream(streamID: streamID), type: .protocolError)
|
||||
return .connectionError(underlyingError: NIOHTTP2Errors.noSuchStream(streamID: streamID), type: .protocolError)
|
||||
default:
|
||||
// This stream must have already been closed.
|
||||
if ignoreClosed {
|
||||
return .ignoreFrame
|
||||
return .ignoreFrame
|
||||
} else {
|
||||
return .connectionError(underlyingError: NIOHTTP2Errors.NoSuchStream(streamID: streamID), type: .streamClosed)
|
||||
return .connectionError(underlyingError: NIOHTTP2Errors.noSuchStream(streamID: streamID), type: .streamClosed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user