Skip to content

Type conformance error while implementing ClientInterceptor #27

@jeevansurendran

Description

@jeevansurendran

Describe the bug

I am trying to create a custom interceptor that propogates few extra header information. I implemented the code as per the example. But i keep getting the error:
Image

My code implementation is somewhere around this:

import GRPCCore

struct AuthInterceptor: ClientInterceptor {
    
    func intercept<Input: Sendable, Output: Sendable>(r
        request: StreamingClientRequest<Input>,
        context: ClientContext,
        next: @Sendable (
            _ request: StreamingClientRequest<Input>,
            _ context: ClientContext
        ) async throws -> StreamingClientResponse<Output>
    ) async throws -> StreamingClientResponse<Output> {
        var request = request
        request.metadata.replaceOrAddString("stoelkf", forKey: "authorization")
        return try await next(request, context)
    }
}

the grpc project version i am using is: 2.1.0, but i also tried with the latest commit in this repo but it didnt help

To reproduce

My Xcode version is 26.0.1 (17A400).
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx26.0

Steps to reproduce the bug you've found:

  1. Create a new iOS project
  2. Import grpc-swift-2
  3. Add the code
import GRPCCore

struct LoggingClientInterceptor: ClientInterceptor {
    
    func intercept<Input: Sendable, Output: Sendable>(r
        request: StreamingClientRequest<Input>,
        context: ClientContext,
        next: @Sendable (
            _ request: StreamingClientRequest<Input>,
            _ context: ClientContext
        ) async throws -> StreamingClientResponse<Output>
    ) async throws -> StreamingClientResponse<Output> {
        print("Invoking method '\(context.descriptor)'")
        let response = try await next(request, context)
        
        switch response.accepted {
        case .success:
            print("Server accepted RPC for processing")
        case .failure(let error):
            print("Server rejected RPC with error '\(error)'")
        }
        
        return response
    }
}

you should get the error:
Image

Expected behaviour

  1. ideally i should have no trouble implementing the protocol and compiler should not throw any error

Additional information

I am new to swift, but i am well versed with grpc. I might be missing something obvious too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions