riok/Kreya

Bug when opening a specific operation

Opened this issue · 9 comments

Describe the bug
When I open an operation, I got the error below (full log at end of ticket):
image

To Reproduce
Steps to reproduce the behavior:
The operation .krop is really classic:

{
"details": {
"path": "/xxxxx",
"method": "POST",
"importedOperationId": "POST /xxxxx",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
]
},
"requests": [
{
"location": "POST xxxxx-request.json",
"contentType": "json"
}
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "POST",
"importStreamId": "fc737b73-2e62-4b12-81cf-6ac355ac7cf1"
}

The JSON content of the "-request" file also very simple, I can't share it here but changing its content doesn't seem to fix the issue anything (even if quitting/restarting Kreya) and its size (a few kB) is fine and not "230158709 bytes".
It's weird because other operations in the same folder with same kind of .krop and request are opening well.

Expected behavior
Do not throw an exception ;)
Or at least point in the right direction to fix the problem (if any)

Screenshots
If applicable, add screenshots to help explain your problem.

Environment & Additional context

{
  "kreyaVersion": "1.16.0-beta.2",
  "releaseChannel": "beta",
  "osDescription": "Microsoft Windows 10.0.19045",
  "osVersion": "Microsoft Windows NT 10.0.19045.0",
  "osArch": "X64",
  "processArch": "X64",
  "runtimeIdentifier": "win-x64",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
}

System.ArgumentException: The JSON value of length 230158709 is too large and not supported.
   at System.Text.Json.ThrowHelper.ThrowArgumentException_ValueTooLarge(Int64 tokenLength)
   at System.Text.Json.Utf8JsonWriter.WriteStringValue(ReadOnlySpan`1 value)
   at System.Text.Json.Serialization.Converters.StringConverter.Write(Utf8JsonWriter writer, String value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
   at System.Text.Json.JsonSerializer.WriteStringAsObject(Object value, JsonTypeInfo jsonTypeInfo)
   at Kreya.Common.Utils.JsonUtil.Serialize(Object data, Type t)
   at Kreya.UI.Mapping.BaseMapper.MapObjectToJRaw(Object source)
   at Kreya.UI.Mapping.BaseMapper.MapObjectToOptionalJRaw(Object source)
   at Kreya.UI.Mapping.OperationMapper.MapToUiOperationWithDetailBase(IOperationWithDetail operation)
   at Kreya.UI.Mapping.OperationMapper.MapToUiOperationWithDetail(IOperationWithDetail operation)
   at Kreya.UI.Invoker.OperationUiService.LoadOperationWithDetails(String operationPath)
   at SpiderEye.Bridge.ApiMethod.InvokeAsync(Object instance, Object parameter)
   at SpiderEye.Bridge.WebviewBridge.InvokeWithDependencyInjection(IDependencyInjectionApiMethod apiMethod, Object parameters)
   at SpiderEye.Bridge.WebviewBridge.InvokeWithDependencyInjection(IDependencyInjectionApiMethod apiMethod, Object parameters)
   at SpiderEye.Bridge.WebviewBridge.ResolveCall(String id, String parameters)
ni507 commented

Hi, there may be a history entry with a large request file.
Can you clear your history cache (Settings > Purge caches > History) and try again to send the request? Note: This will remove all history entries for all operations in all projects.

Hello,
Thank you for your proposal.

I have tried Purge > Operation history and it didn't work.
I also tried "Cleanup Database" and "Local application data files" (I am not exactly knowing what they are, it's just a try ;) ) and it didn't work either.
I have restarted Kreya between each attempt (because if one load attempt fails, it's not anymore possible to open it again as far as I can see).

I don't know if it can help to figure the problem but I noticed the error slightly changed (it was already the case before all the "cleans" tries), the length is now greater : image. If you point me to the right folder (somewhere in user's appdata I guess) maybe I can tell you which file it is.

ni507 commented

Okay, thanks for checking. I investigated further and found that it was due to the details in the .krop file. Does your path contain any path params {xy} or does the importedOperationId contain any path params such as:

"details": {
    "path": "/v1/books/{id}",
    "method": "GET",
    "importedOperationId": "GET /v1/books/{id}",
    "headers": [],
    "pathParams": [
      {
        "key": "id",
        "value": "1"
      }
    ]
  },

Or are there some unusual characters in these two paths? Or are they perhaps deeply nested?

Hello,
No it's really simple :
"path": "/v2.0/SomethingInEnglish",
"method": "POST",
"importedOperationId": "POST /v2.0/SomethingInEnglish"

The other (working) endpoints have the same structure.
The POST itself should not have returned a huge amount of data if it had worked (I tell you this regarding your previous remark based on "operation history")

ni507 commented

Okay, this is strange.
As the operation is imported, can you try to create the operation from scratch without the importer?
Create an empty operation and fill in everything by hand. (Path, request, etc.) Does this work?

Without the importer it works well.
And with the importer, as my existing operation it crashes on opening (but the operation itself is properly created, including its "request" file of almost 200kB)

ni507 commented

Okay, I may have found the problem. It looks like it has to do with the schema of your request that is imported and loaded when the operation is opened.
Can you share how your request body is structured from this endpoint in the swagger config?

Hello !
What do you mean by "how it is structured" ?
I am sorry but I will absolutely not be able to share neither the swagger, neither the request. My customer is quite sensitive ;)

We can understand that of course. Kreya creates a JSON schema to validate the request and provide suggestions. In your case, the JSON schema seems to get very big. We would have needed the Swagger/OpenAPI document to analyse this further.

In the meantime, we have implemented a workaround (limit JSON schema size) so that the operation can still be used.