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

+5 -5
View File
@@ -600,7 +600,7 @@ internal extension HTTPResponseHead {
// A response head should have only one psuedo-header. We strip it off.
let statusHeader = try headers.peekPseudoHeader(name: ":status")
guard let integerStatus = Int(statusHeader, radix: 10) else {
throw NIOHTTP2Errors.InvalidStatusValue(statusHeader)
throw NIOHTTP2Errors.invalidStatusValue(statusHeader)
}
let status = HTTPResponseStatus(statusCode: integerStatus)
self.init(version: .init(major: 2, minor: 0), status: status, headers: HTTPHeaders(regularHeadersFrom: headers))
@@ -622,7 +622,7 @@ extension HPACKHeaders {
for (fieldName, fieldValue, _) in self {
if name == fieldName {
guard headerValue == nil else {
throw NIOHTTP2Errors.DuplicatePseudoHeader(name)
throw NIOHTTP2Errors.duplicatePseudoHeader(name)
}
headerValue = fieldValue
}
@@ -631,7 +631,7 @@ extension HPACKHeaders {
if let headerValue = headerValue {
return headerValue
} else {
throw NIOHTTP2Errors.MissingPseudoHeader(name)
throw NIOHTTP2Errors.missingPseudoHeader(name)
}
}
}
@@ -660,7 +660,7 @@ extension HTTPHeaders {
for header in requestHead.headers {
if header.name.lowercased() == "host" {
if authorityHeader != nil {
throw NIOHTTP2Errors.DuplicateHostHeader()
throw NIOHTTP2Errors.duplicateHostHeader()
}
authorityHeader = header.value
@@ -671,7 +671,7 @@ extension HTTPHeaders {
// Now we go back and fill in the authority header.
guard let actualAuthorityHeader = authorityHeader else {
throw NIOHTTP2Errors.MissingHostHeader()
throw NIOHTTP2Errors.missingHostHeader()
}
newHeaders[3].1 = actualAuthorityHeader