Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.86k stars 450 forks source link

Added explicit error handling #8161

Closed qstokkink closed 2 months ago

qstokkink commented 2 months ago

Fixes #8141

This PR:

Notes:


Expected core error status example

diff --git a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
index 56841c8d8..05b439503 100644
--- a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
+++ b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
@@ -101,6 +101,8 @@ class DownloadsEndpoint(RESTEndpoint):
         """
         download_config = DownloadConfig.from_defaults(self.download_manager.config)

+        return None, "Cannot set anonymous download without safe seeding enabled"
+
         anon_hops = parameters.get('anon_hops')
         safe_seeding = bool(parameters.get('safe_seeding', 0))

screenshot

Unexpected core error status example

diff --git a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
index 56841c8d8..c3f664a35 100644
--- a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
+++ b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py
@@ -270,7 +270,7 @@ class DownloadsEndpoint(RESTEndpoint):
         get_pieces = params.get('get_pieces', '0') == '1'
         get_availability = params.get('get_availability', '0') == '1'
         unfiltered = not params.get('infohash')
-
+        raise RuntimeError("oh no")
         checkpoints = {
             TOTAL: self.download_manager.checkpoints_count,
             LOADED: self.download_manager.checkpoints_loaded,

screenshot2

TypeScript error example

diff --git a/src/tribler/ui/src/services/tribler.service.ts b/src/tribler/ui/src/services/tribler.service.ts
index 60d3fefff..e98cf7803 100644
--- a/src/tribler/ui/src/services/tribler.service.ts
+++ b/src/tribler/ui/src/services/tribler.service.ts
@@ -50,6 +50,7 @@ export class TriblerService {

     async getDownloads(infohash: string = '', getPeers: boolean = false, getPieces: boolean = false): Promise<undefined | ErrorDict | Download[]> {
         try {
+            throw Error("Oh no!");
             return (await this.http.get(`/downloads?infohash=${infohash}&get_peers=${+getPeers}&get_pieces=${+getPieces}`)).data.downloads;
         } catch (error) {
             return formatAxiosError(error as Error | AxiosError);

screenshot3

TypeScript compiler errors when not safeguarding GUI code

diff --git a/src/tribler/ui/src/pages/Downloads/index.tsx b/src/tribler/ui/src/pages/Downloads/index.tsx
index f24f000e8..de3ad9c1d 100644
--- a/src/tribler/ui/src/pages/Downloads/index.tsx
+++ b/src/tribler/ui/src/pages/Downloads/index.tsx
@@ -159,6 +159,7 @@ export default function Downloads({ statusFilter }: { statusFilter: number[] })

         // Don't bother the user on error, just try again later.
         const response = await triblerService.getDownloads(infohash, !!infohash, !!infohash);
+        console.log(response[0]);
         if (response !== undefined && !isErrorDict(response)) {
             setDownloads(response.filter((download: Download) => {
                 return statusFilter.includes(download.status_code);
>npm run build

> tribler-webui@0.1.0 build
> tsc && vite build

src/pages/Downloads/index.tsx:162:21 - error TS18048: 'response' is possibly 'undefined'.

162         console.log(response[0]);
                        ~~~~~~~~

src/pages/Downloads/index.tsx:162:21 - error TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'ErrorDict | Download[]'.
  Property '0' does not exist on type 'ErrorDict | Download[]'.

162         console.log(response[0]);
                        ~~~~~~~~~~~

Found 2 errors in the same file, starting at: src/pages/Downloads/index.tsx:162