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

DIo Causes Random FormatExceptions When Parsing JSON Response. JSON Response is 100% correct Format. #1930

Closed
Abdullah-Rashed opened this issue Aug 9, 2023 · 10 comments
Labels
i: wontfix This will not be worked on

Comments

@Abdullah-Rashed
Copy link

Package

dio

Version

5.1.1

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.3208], locale en-US)
    • Flutter version 3.10.0 on channel stable at C:\My Stuff\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 84a1e904f4 (3 months ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\abdullah.rashed\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.27)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.33801.447
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.81.0)
    • VS Code at C:\Users\abdullah.rashed\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.70.0

[√] Connected device (4 available)
    • sdk gphone x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)          • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.3208]
    • Chrome (web)               • chrome        • web-javascript • Google Chrome 115.0.5790.171
    • Edge (web)                 • edge          • web-javascript • Microsoft Edge 114.0.1823.67

[√] Network resources
    • All expected network resources are available.

• No issues found!

Dart Version

3.0.0 stable

Steps to Reproduce

  1. Setup a dio client class
  2. Retrieve JSON from server
  3. It is completely random. It cannot be reproduced on command. When the JSON response is a JSON object that has data.

Expected Result

Normal Response from Dio function.

Actual Result

I/flutter ( 8544): onChange -- RewardsCubit, Change { currentState: Instance of 'RewardsLoadingState', nextState: Instance of 'RewardsErrorState' }
[log] FormatException: Unexpected end of input (at character 4344)
...b_category/xhyXu50db7CYmPeZIoo6snFVvjedlVrdhhYAk0ZW.webp","disable":true}]

image

@Abdullah-Rashed Abdullah-Rashed added h: need triage This issue needs to be categorized s: bug Something isn't working labels Aug 9, 2023
@kuhnroyal
Copy link
Member

It is very likely that your JSON content is broken. Without the actual content that breaks, we can not do any thing here.

@Abdullah-Rashed
Copy link
Author

Abdullah-Rashed commented Aug 9, 2023

here is the JSON response format.

{
    "success": true,
    "responseMessage": "SILVER NOT ENOUGH ",
    "responseCode": 1117,
    "data": [
        {
            "item_id": 194,
            "silver": 2479.95,
            "name": "PUBG Mobile    60 UC",
            "description": "PUBG",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 195,
            "silver": 24930,
            "name": "PUBG Mobile 600 + 60 UC",
            "description": "PUBG",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 192,
            "silver": 12480,
            "name": "PUBG Mobile 300 + 25 UC",
            "description": "PUBG",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 102,
            "silver": 2850,
            "name": "FreeFire USD 1 (100 + 10 Diamonds)",
            "description": "FreeFire",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 104,
            "silver": 5700,
            "name": "FreeFire USD 2 (210 + 21 Diamonds)",
            "description": "FreeFire",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 103,
            "silver": 28500,
            "name": "FreeFire USD 10 (1080 + 108 Diamonds)",
            "description": "FreeFire",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 46,
            "silver": 29400.000000000004,
            "name": "Amazon US USD 10 (US)",
            "description": "Amazon US",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 61,
            "silver": 11460,
            "name": "Apple & iTunes Card US USD 4 (US)",
            "description": "Apple Card US",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 63,
            "silver": 14325.000000000002,
            "name": "Apple & iTunes Card US USD 5 (US)",
            "description": "Apple Card US",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 54,
            "silver": 5730,
            "name": "Apple & iTunes Card US USD 2 (US)",
            "description": "Apple Card US",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 155,
            "silver": 27300,
            "name": "Nintendo eShop US USD 10 (US)",
            "description": "Nintendo eShop US",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 201,
            "silver": 14100,
            "name": "Razer Gold 5$ Global",
            "description": "Razer Gold Pins",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 307,
            "silver": 2700,
            "name": "Jawaker 4250 Token",
            "description": "Jawaker 4250 Token",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 308,
            "silver": 13500,
            "name": "Jawaker 32500 Token",
            "description": "Jawaker 32500 Token",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 309,
            "silver": 27000,
            "name": "Jawaker 70000 Token",
            "description": "Jawaker 70000 Token",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 1129,
            "silver": 2820,
            "name": "Razer Gold - $1 (Global)",
            "description": "Razer Gold - USD 1 (Global)",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 1130,
            "silver": 5640,
            "name": "Razer Gold - $2 (Global)",
            "description": "Razer Gold - USD 2 (Global)",
            "photo": "",
            "disable": true
        },
        {
            "item_id": 133,
            "silver": 57000,
            "name": "Mobile Legends 1167 Diamonds",
            "description": "Mobile Legends",
            "photo": "",
            "disable": true
        }
    ]
}

I should stress that all other APIs work correctly (until they don't.), and that the JSON format is correct.

@AlexV525
Copy link
Member

AlexV525 commented Aug 9, 2023

We don't know what happened because you seem to have mounted multiple interceptors. It would be helpful if you could get rid of the project setup and make a minimal reproducible example.

@AlexV525
Copy link
Member

AlexV525 commented Aug 9, 2023

But from your log, the ending } seems to be missing and there is a space instead. You might want to check if there are any transformers that manipulated your bytes or try to convert from raw bytes to see if it's correct.

@Abdullah-Rashed
Copy link
Author

We don't know what happened because you seem to have mounted multiple interceptors. It would be helpful if you could get rid of the project setup and make a minimal reproducible example.

The only Interceptor I have setup is the onError. To catch what causes the exception. Without the interceptor it would return a null response with a DioError:[unknown] null.

@Abdullah-Rashed
Copy link
Author

But from your log, the ending } seems to be missing and there is a space instead. You might want to check if there are any transformers that manipulated your bytes or try to convert from raw bytes to see if it's correct.

I did. And same behavior. Seems like every now and then it throws a JsonFormarException at the same place (always at the very last Json Object in the response array). If the JSON was faulty, wouldn't it not work at all? it's the behavior of sometimes it causes an exception that's puzzling me.

@AlexV525
Copy link
Member

AlexV525 commented Aug 9, 2023

As far as I can tell this should not be a Dio's problem, but if you can manage to export the raw bytes of the "Malformed" JSON or your API can be shared secretly, send it to cfug-team@googlegroups.com and we'll take a look.

@Abdullah-Rashed
Copy link
Author

As far as I can tell this should not be a Dio's problem, but if you can manage to export the raw bytes of the "Malformed" JSON or your API can be shared secretly, send it to cfug-team@googlegroups.com and we'll take a look.

Sure! I'll be sending the API itself over to you shortly.

@AlexV525 AlexV525 added h: need more info Further information is requested i: no useful information and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Aug 9, 2023
@Abdullah-Rashed
Copy link
Author

ISSUE HAS BEEN IDENTIFIED

It appears that the local testing environment of the company was intercepting the responses and messing with the response (though it looks perfectly fine). Server testing environment was not causing the exception to happen.

It's notable that both Dio and http packages caused the same exception at the same place. (http caused it way less times)
You can go ahead and close the ticket. My apologies for the inconvenience

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
@AlexV525
Copy link
Member

Sounds like http was not as good as dio when identifying issues that should occur. :)

@AlexV525 AlexV525 added i: wontfix This will not be worked on and removed h: need more info Further information is requested i: no useful information labels Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants