Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Discord: Fixing Array Length Mismatch Error in RPC Handler #4390

Open
effect-bot opened this issue Feb 4, 2025 · 3 comments
Open

From Discord: Fixing Array Length Mismatch Error in RPC Handler #4390

effect-bot opened this issue Feb 4, 2025 · 3 comments

Comments

@effect-bot
Copy link

Summary

The conversation revolves around an error encountered in an RPC handler from the Effect Typescript library. The error message states: "handler must return an array of responses with the same length as the requests".

  • Issue Understanding: The error appears when there is a mismatch between the number of requests sent and the number of responses received. This happens in batched requests where the client expects a response for each request.

  • Potential Causes: One user identified an issue when doing custom encoding server-side using msw. Another pointed out that the error might occur if the RPC schema is incorrect, specifically if an undefined error is thrown.

  • Resolution Attempts: Users suggest checking the schema and ensuring it aligns with the RPC definitions. Also, custom implementations or encoding might need review.

Key Takeaways:

  1. Ensure request and response arrays match in length during batched RPC calls.
  2. Check the RPC schema for mismatches or missing error definitions.
  3. Consider reviewing any custom server-side handling or encoding if discrepancies occur.
  4. Improved error messages could be beneficial, and a community member proposed contributing a PR for better error handling.

Discord thread

https://discord.com/channels/795981131316985866/1296767660490625034

@evelant
Copy link
Contributor

evelant commented Feb 4, 2025

If your rpc handler fails with an error that is not defined in your rpc schema you get a very unhelpful error on the client: RuntimeException: @effect/rpc: handler must return an array of responses with the same length as the requests.. I'll see if I can make a PR to improve error handling in this case.

@tim-smart
Copy link
Contributor

FYI: #4362

@evelant
Copy link
Contributor

evelant commented Feb 4, 2025

Ah is that likely to resolve this? If so I won't bother with a PR.

edit: a quick skim and it looks like a total rewrite of rpc so I'd guess yes, this will no longer be an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants