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:
George Barnett authored and GitHub committed 2020-09-24 15:21:58 +01:00
1 parent 28d94c489d
commit 440d64d99a
33 files changed
+1598 -233

No files matched your search

+6 -6
View File
@@ -326,7 +326,7 @@ struct HTTP2FrameDecoder {
}
guard clientMagic == HTTP2FrameDecoder.clientMagicBytes else {
throw NIOHTTP2Errors.BadClientMagic()
throw NIOHTTP2Errors.badClientMagic()
}
self.state = .accumulatingFrameHeader(.init(unusedBytes: state.pendingBytes))
@@ -349,7 +349,7 @@ struct HTTP2FrameDecoder {
// Not a DATA frame. Before we move on, do a quick preflight: if this frame header is for a frame that will
// definitely violate SETTINGS_MAX_HEADER_LIST_SIZE, quit now.
if header.type == 1 && header.length > self.headerDecoder.maxHeaderListSize {
throw NIOHTTP2Errors.ExcessivelyLargeHeaderBlock()
throw NIOHTTP2Errors.excessivelyLargeHeaderBlock()
}
self.state = .accumulatingData(AccumulatingPayloadParserState(fromIdle: state, header: header))
@@ -572,7 +572,7 @@ struct HTTP2FrameDecoder {
// Check whether there is any possibility of this payload decompressing and fitting in max header list size.
// If there isn't, kill it.
guard state.accumulatedPayload.readableBytes + header.length <= self.headerDecoder.maxHeaderListSize else {
throw NIOHTTP2Errors.ExcessivelyLargeHeaderBlock()
throw NIOHTTP2Errors.excessivelyLargeHeaderBlock()
}
self.state = .accumulatingContinuationPayload(AccumulatingContinuationPayloadParserState(fromAccumulatingHeaderBlockFragments: state, continuationHeader: header))
@@ -1031,7 +1031,7 @@ struct HTTP2FrameEncoder {
case .data(let dataContent):
if dataContent.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
if dataContent.endStream {
@@ -1043,7 +1043,7 @@ struct HTTP2FrameEncoder {
case .headers(let headerData):
if headerData.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
flags.insert(.endHeaders)
@@ -1099,7 +1099,7 @@ struct HTTP2FrameEncoder {
case .pushPromise(let pushPromiseData):
if pushPromiseData.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
let streamVal: UInt32 = UInt32(pushPromiseData.pushedStreamID)