ansible / vscode-ansible

vscode/vscodium extension for providing Ansible auto-completion and integrating quality assurance tools like ansible-lint, ansible syntax check, yamllint, molecule and ansible-test.
https://ansible.readthedocs.io/projects/vscode-ansible/
MIT License
360 stars 86 forks source link

Empty Response feedback for 204 on Lightspeed #1319

Closed hasys closed 4 months ago

hasys commented 4 months ago

VS Code counterpart of https://github.com/ansible/ansible-ai-connect-service/pull/979

github-actions[bot] commented 4 months ago

Label error. Requires exactly 1 of: bug, enhancement, major, minor, patch, skip-changelog. Found:

github-actions[bot] commented 4 months ago

Label error. Requires exactly 1 of: bug, enhancement, major, minor, patch, skip-changelog. Found:

hasys commented 4 months ago

Hello @manstis, @robinbobbitt, I updated the PR

now when server sends 204, user will see: Screenshot 2024-05-30 at 13 14 28

For the record. Times to times (pretty often) instead of the screenshot above user will see: Screenshot 2024-05-30 at 13 25 57

The error is happening here: https://github.com/ansible/vscode-ansible/blob/bf79bf62b0563928db7c5c00d119b7410dc6a82d/src/features/lightspeed/api.ts#L117

The request throws an Error: Parse Error: Expected HTTP/ error and user see the general error after it. I have tried to understand what is going on there, but I think I already spent too much there and I am out of ideas.

Since I think it is not related to the issue I am working on I suggest to report it as separate issue and deal with it in separate PR.

P.S. There is a diff for two requests: successful and not successful:

kgaevski:~ % diff file1 file2
3,4c3,4
<                 b'pache2\\n"],"model":"mocked_wca_client","suggestionId":"d8259'
<                 b'b8f-402d-4ed9-8ffa-77dec8e67669"}'],
---
>                 b'pache2\\n"],"model":"mocked_wca_client","suggestionId":"10e93'
>                 b'2ab-d9af-4fa7-a18c-d23238a3cc34"}'],
12c12
<  'accepted_renderer': <rest_framework.renderers.JSONRenderer object at 0x13a6e6b10>,
---
>  'accepted_renderer': <rest_framework.renderers.JSONRenderer object at 0x13a6e7990>,
24c24
<                       'view': <ansible_ai_connect.ai.api.views.Completions object at 0x13a689f90>},
---
>                       'view': <ansible_ai_connect.ai.api.views.Completions object at 0x13a7e64d0>},

And the full response dump:

{'_charset': None,
 '_container': [b'{"predictions":["      ansible.builtin.apt:\\n        name: a'
                b'pache2\\n"],"model":"mocked_wca_client","suggestionId":"10e93'
                b'2ab-d9af-4fa7-a18c-d23238a3cc34"}'],
 '_handler_class': None,
 '_is_rendered': True,
 '_post_render_callbacks': [],
 '_reason_phrase': None,
 '_request': None,
 '_resource_closers': [],
 'accepted_media_type': 'application/json',
 'accepted_renderer': <rest_framework.renderers.JSONRenderer object at 0x13a6e7990>,
 'closed': False,
 'content_type': None,
 'context_data': None,
 'cookies': <SimpleCookie: >,
 'data': None,
 'exception': False,
 'headers': {'Content-Type': 'None', 'Allow': 'POST, OPTIONS', 'Content-Security-Policy-Report-Only': "default-src 'self' data:; style-src 'self' 'unsafe-inline'", 'Content-Length': '0'},
 'renderer_context': {'args': (),
                      'kwargs': {},
                      'request': <rest_framework.request.Request: POST '/api/v0/ai/completions/'>,
                      'response': <Response status_code=204, "None">,
                      'view': <ansible_ai_connect.ai.api.views.Completions object at 0x13a7e64d0>},
 'status_code': 204,
 'tasks': [{'collection': 'ansible.builtin',
            'module': 'ansible.builtin.apt',
            'name': 'install go',
            'prediction': '      ansible.builtin.apt:\n'
                          '        name: apache2\n'}],
 'template_name': None,
 'using': None}
hasys commented 4 months ago

Created Jira issue for the remaining issue: https://issues.redhat.com/browse/AAP-24828