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

Invalid value too long string exceeded 'maxCharBufSize' #2458

Closed
kaaveland opened this issue Nov 6, 2024 · 6 comments
Closed

Invalid value too long string exceeded 'maxCharBufSize' #2458

kaaveland opened this issue Nov 6, 2024 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers server Issue related to caliban server

Comments

@kaaveland
Copy link
Contributor

I should probably be able to figure this one out on my own, but I haven't been able to. I'm getting this error for very long strings in graphql requests to my graphql api -- it's simply being returned as a 400 Bad Request. I would like to adjust jsoniters maxCharBufSize, which as far as I can tell, can be set in ReaderConfig:

https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-core/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/ReaderConfig.scala#L38

I could also provide by own instance to JsonReader:

https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-core/js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala#L36

Alternatively, perhaps set up caliban to use a different json library, although #2341 makes it seem like the project wants to avoid this in the future.

Is there an easy way to convince caliban to accept strings that are a little longer?

@ghostdogpr
Copy link
Owner

Ah actually we did this for Caliban Client: #2085
I think we could do the same on the server side too. Wanna make a PR?

@ghostdogpr ghostdogpr added enhancement New feature or request good first issue Good for newcomers server Issue related to caliban server labels Nov 6, 2024
@kaaveland
Copy link
Contributor Author

I'll take a stab at this 👍

What's the right place to start, should I just start to looking for usages of readFromString in core?

@ghostdogpr
Copy link
Owner

ghostdogpr commented Nov 7, 2024

So for the quick adapter that would be in QuickRequestHandler (look for readFromString and readFromArray). For the tapir-based adapters it's trickier because the decoding is done by Tapir, and I am not sure if they let you configure it. It requires some research (I see that when we import sttp.tapir.json.jsoniter._, it calls TapirJsonJsoniter so maybe we have to make a custom version of that).

@kaaveland
Copy link
Contributor Author

It looks like doing something like this is fairly simple for the tapir adapters:

object MaxCharBufSizeJsonJsoniter extends TapirJsonJsoniter {
  override lazy val readerConfig: ReaderConfig =
    ReaderConfig
      .withAppendHexDumpToParseException(false)
      .withMaxCharBufSize(2147483645)
      .withMaxBufSize(2147483645)
}

Then just edit the imports. That's strictly speaking different than the way it was solved in the client package, but functionally similar (the buffer size error won't occur unless you send a DVD). Is that an acceptable solution, or do we need to be able to pass options to ReaderConfig?

@ghostdogpr
Copy link
Owner

Sounds acceptable!

@ghostdogpr
Copy link
Owner

Closed by #2459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers server Issue related to caliban server
Projects
None yet
Development

No branches or pull requests

2 participants