Jeeaaasus / youtube-dl

Automated yt-dlp Docker image
https://hub.docker.com/r/jeeaaasustest/youtube-dl/
MIT License
258 stars 33 forks source link

WebUI: Editing archive when none exists causes internal server error #55

Closed fpiesche closed 2 years ago

fpiesche commented 2 years ago

The web UI should probably handle this gracefully, e.g. by just loading an edit box with no contents. An alternative option would be to include an empty archive.txt with the default config.

Stacktrace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/local/lib/python3.9/dist-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/dist-packages/fastapi/applications.py", line 208, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/dist-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/dist-packages/starlette/exceptions.py", line 82, in __call__
    raise exc
  File "/usr/local/lib/python3.9/dist-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 656, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 61, in app
    response = await func(request)
  File "/usr/local/lib/python3.9/dist-packages/fastapi/routing.py", line 226, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.9/dist-packages/fastapi/routing.py", line 159, in run_endpoint_function
    return await dependant.call(**values)
  File "/app/webserver/youtube-dl.py", line 80, in edit_archive
    async with aiofiles.open('/config/archive.txt') as f:
  File "/usr/local/lib/python3.9/dist-packages/aiofiles/base.py", line 75, in __aenter__
    self._obj = await self._coro
  File "/usr/local/lib/python3.9/dist-packages/aiofiles/threadpool/__init__.py", line 80, in _open
    f = yield from loop.run_in_executor(executor, cb)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
FileNotFoundError: [Errno 2] No such file or directory: '/config/archive.txt'

I'll try and put together a PR to fix this tomorrow.

Jeeaaasus commented 2 years ago

Hi there @fpiesche :) yep, it should probably test if the file exists and if not create it and then continue on and open it as usual.

Side note, the webui was thrown together only to be functional and it's overall not great.