Repository: apple/swift-nio
File: Sources/NIOHTTP1/HTTPServerPipelineHandler.swift (Swift)

Code before:
            self.nextExpectedInboundMessage = .head
            self.nextExpectedOutboundMessage = .head
        }
    }

    private enum ConnectionStateAction {
        /// A precondition has been violated. Should send an error down the pipeline
        case warnPreconditionViolated(message: String)

        /// A further state change was attempted when a precondition has already been violated.
        /// Should force close this connection
        case forceCloseConnection

        /// Nothing to do
        case none
    }

    public struct ConnectionStateError: Error, CustomStringConvertible, Hashable {
        enum Base: Hashable, CustomStringConvertible {
            /// A precondition was violated
            case preconditionViolated(message: String)

            var description: String {
                switch self {
                case .preconditionViolated(let message):
                    return message
                }
            }
        }

        var base: Base
        var file: String
        var line: Int

        init(base: Base, file: String, line: Int) {
            self.base = base
            self.file = file
            self.line = line
        }

        public static func ==(lhs: ConnectionStateError, rhs: ConnectionStateError) -> Bool {
            lhs.base == rhs.base
        }

        public func hash(into hasher: inout Hasher) {
            hasher.combine(self.base)
        }

        /// A precondition was violated
        public static func preconditionViolated(message: String, file: String = #fileID, line: Int = #line) -> Self {
            .init(base: .preconditionViolated(message: message), file: file, line: line)

Review comment (suggestion):
We should add a `"precondition violated"` to this description as well

Code after:
            self.nextExpectedInboundMessage = .head
            self.nextExpectedOutboundMessage = .head
        }
    }

    private enum ConnectionStateAction {
        /// A precondition has been violated. Should send an error down the pipeline
        case warnPreconditionViolated(message: String)

        /// A further state change was attempted when a precondition has already been violated.
        /// Should force close this connection
        case forceCloseConnection

        /// Nothing to do
        case none
    }

    public struct ConnectionStateError: Error, CustomStringConvertible, Hashable {
        enum Base: Hashable, CustomStringConvertible {
            /// A precondition was violated
            case preconditionViolated(message: String)

            var description: String {
                switch self {
                case .preconditionViolated(let message):
                    return "Precondition violated \(message)"
                }
            }
        }

        private var base: Base
        private var file: String
        private var line: Int

        private init(base: Base, file: String, line: Int) {
            self.base = base
            self.file = file
            self.line = line
        }

        public static func ==(lhs: ConnectionStateError, rhs: ConnectionStateError) -> Bool {
            lhs.base == rhs.base
        }

        public func hash(into hasher: inout Hasher) {
            hasher.combine(self.base)
        }

        /// A precondition was violated
        public static func preconditionViolated(message: String, file: String = #fileID, line: Int = #line) -> Self {
            .init(base: .preconditionViolated(message: message), file: file, line: line)