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

Better handling of non-existent attachment attachment paths #826

Closed
1 task
FasterSpeeding opened this issue Oct 7, 2021 · 1 comment · Fixed by #1046
Closed
1 task

Better handling of non-existent attachment attachment paths #826

FasterSpeeding opened this issue Oct 7, 2021 · 1 comment · Fixed by #1046
Labels
enhancement New feature or request

Comments

@FasterSpeeding
Copy link
Collaborator

Summary

Consider checking if file attachments exist before passing them through to aiohttp.

Problem

The current error for a file not being found is the following

aiohttp.client_exceptions.ClientOSError: [Errno 13] Can not write request body for

This is unintuitive and directs away from the actual problem of the file not existing and if we had an explicit check before the file was handed over to aiohttp we could improve the user experience when dealing with this issue.

Ideal implementation

Check if file attachments exist before passing them through to aiohttp.

Checklist

  • I have searched the issue tracker and have made sure it's not a duplicate.
    If it is a follow up of another issue, I have specified it.
@FasterSpeeding FasterSpeeding added the enhancement New feature or request label Oct 7, 2021
@davfsa
Copy link
Member

davfsa commented Nov 9, 2021

The ClientOSError does seem to have the "true" error attached as a cause, maybe we could just point to that instead of doing anything special:

Traceback (most recent call last):
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 583, in write_bytes
    await self.body.write(writer)
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/multipart.py", line 901, in write
    await part.write(writer)
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/payload.py", line 446, in write
    chunk = await self._iter.__anext__()
  File "/home/davfsa/coding/hikari/hikari/files.py", line 787, in __aiter__
    fp = await loop.run_in_executor(self.executor, self._open, path)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/davfsa/coding/hikari/hikari/files.py", line 812, in _open
    return open(path, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/davfsa/coding/test-bots/test.pyi'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/davfsa/coding/test-bots/sokudo.py", line 139, in evaluate
    result = await locals()["___invoke___"](bot, event)
  File "<string>", line 2, in ___invoke___
  File "/home/davfsa/coding/hikari/hikari/messages.py", line 1276, in respond
    return await self.app.rest.create_message(
  File "/home/davfsa/coding/hikari/hikari/impl/rest.py", line 1343, in create_message
    return await self._create_message(
  File "/home/davfsa/coding/hikari/hikari/impl/rest.py", line 1309, in _create_message
    response = await self._request(route, form_builder=form, query=query, no_auth=no_auth)
  File "/home/davfsa/coding/hikari/hikari/impl/rest.py", line 743, in _request
    response = await live_attributes.still_alive().client_session.request(
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/client.py", line 559, in _request
    await resp.start(conn)
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 898, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
  File "/home/davfsa/coding/hikari/.venv/lib/python3.9/site-packages/aiohttp/streams.py", line 614, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 2] Can not write request body for https://discord.com/api/v8/channels/654355510669344798/messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants