FriendTeamInc / VodBot

A command line interface VOD and Clip manager for Twitch.
MIT License
14 stars 1 forks source link

Error on upload causes a crash instead of being reported and handled safely #69

Closed NotQuiteApex closed 1 year ago

NotQuiteApex commented 1 year ago
apex@serv ~ $ vodbot upload all
Loading stages... Authenticating with Google... done.
About to upload 1 stage(s).
Slicing stage part (1/1) `1863427077` (0:0:0 - EOF)
Traceback (most recent call last):% (6.4 GB/16.3 GB)...
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 63, in _upload_artifact
    status, resp = response_upload.next_chunk()
  File "/home/apex/.local/lib/python3.10/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/apex/.local/lib/python3.10/site-packages/googleapiclient/http.py", line 1084, in next_chunk
    resp, content = http.request(
  File "/home/apex/.local/lib/python3.10/site-packages/google_auth_httplib2.py", line 218, in request
    response, content = self.http.request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1725, in request
    (response, content) = self._request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1441, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1393, in _conn_request
    response = conn.getresponse()
  File "/usr/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/usr/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.10/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.10/ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/apex/.local/bin/vodbot", line 8, in <module>
    sys.exit(deffered_main())
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/__main__.py", line 82, in deffered_main
    main()
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/__main__.py", line 184, in main
    import_module(".commands.upload", "vodbot").run(args)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 357, in run
    video_id = upload_video(conf, service, stage)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 145, in upload_video
    uploaded = _upload_artifact(f"stage video #r`#fM{stagedata.id}#r`", response_upload, getting_video=True, filesize=filesize)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 92, in _upload_artifact
    print_error([err])
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 57, in print_error
    cprint(f"#fY#dWARN: An HTTP error has occurred ({errn}/{errn_max}), retyring in {secs} seconds... ({', '.join(f)})#r")
TypeError: sequence item 0: expected str instance, TimeoutError found

Seems that the main error is the ', '.join(f), where f is a list of errors that need to be converted to a string from TimeoutError. This mishandling of exceptions makes the upload fail when it could be recoverable.

NotQuiteApex commented 1 year ago
apex@serv ~ $ vodbot upload all
Loading stages... Authenticating with Google... done.
About to upload 1 stage(s).
Slicing stage part (1/1) `1863427077` (0:0:0 - EOF)
Traceback (most recent call last):% (5.3 GB/16.3 GB)...
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 63, in _upload_artifact
    status, resp = response_upload.next_chunk()
  File "/home/apex/.local/lib/python3.10/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/apex/.local/lib/python3.10/site-packages/googleapiclient/http.py", line 1084, in next_chunk
    resp, content = http.request(
  File "/home/apex/.local/lib/python3.10/site-packages/google_auth_httplib2.py", line 218, in request
    response, content = self.http.request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1725, in request
    (response, content) = self._request(
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1441, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1364, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1076, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.10/http/client.py", line 998, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.10/ssl.py", line 1237, in sendall
    v = self.send(byte_view[count:])
  File "/usr/lib/python3.10/ssl.py", line 1206, in send
    return self._sslobj.write(data)
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2396)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/apex/.local/bin/vodbot", line 8, in <module>
    sys.exit(deffered_main())
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/__main__.py", line 82, in deffered_main
    main()
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/__main__.py", line 184, in main
    import_module(".commands.upload", "vodbot").run(args)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 357, in run
    video_id = upload_video(conf, service, stage)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 145, in upload_video
    uploaded = _upload_artifact(f"stage video #r`#fM{stagedata.id}#r`", response_upload, getting_video=True, filesize=filesize)
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 92, in _upload_artifact
    print_error([err])
  File "/home/apex/.local/lib/python3.10/site-packages/vodbot/commands/upload.py", line 57, in print_error
    cprint(f"#fY#dWARN: An HTTP error has occurred ({errn}/{errn_max}), retyring in {secs} seconds... ({', '.join(f)})#r")
TypeError: sequence item 0: expected str instance, SSLEOFError found

Seems this is a general issue with error reporting, oops! Simple solution would be to just do something like f = [str(x) for x in f] before the printing.