Effect CommunityEC
Effect Community2y ago
6 replies
imagio

Issue with Rpc call and missing services

With the new version of Rpc I'm having a problem calling an Rpc in some cases. When the response comes it it fails because it can't find ServerRequest or Scope in context.

Error: Service not found: @effect/platform/Http/ServerRequest
Error: Service not found: effect/Scope


This happens when using the following unsafeCallRpc function. A "normal" Rpc call works, it only fails when some legacy code tries to use this unsafeCallRpc.

const _unsafeCallRpc =
    (getRuntime: () => Promise<Runtime.Runtime<RpcWorkingRef | DatabaseService>>) =>
    async <T extends RpcAuthenticatedReqs>(method: T) => {
        return pipe(
            Effect.flatMap(getRpcAuthenticatedClient, client => {
                const m = client(method)
                if (Effect.isEffect(m)) {
                    return m as Effect.Effect<Request.Request.Success<T>, Request.Request.Error<T>, never>
                } else {
                    return Stream.runCollect(m) as Effect.Effect<
                        Request.Request.Success<T>,
                        Request.Request.Error<T>,
                        never
                    >
                }
            }),
            Effect.tapErrorCause(e => Effect.logError(e)),
            Effect.withLogSpan(`unsafeCallRpc`),
            Effect.annotateLogs(`method`, method._tag),
            Runtime.runPromise(await getRuntime()),
        )
    }


This unsafeCallRpc worked fine with the previous version of Rpc. I'm sure the runtime is correct, it's the global runtime used everywhere in my app. Any ideas why or where it's failing to get ServerRequest and Scope in this case?
Was this page helpful?