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

READY: Added explicit error handling #8161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qstokkink
Copy link
Contributor

@qstokkink qstokkink commented Sep 17, 2024

Fixes #8141

This PR:

  • Adds explicit error handling to all tribler/ipv8 service calls.

Notes:

  • Depending on the call, error handling can be either silent or involve a little toast popup describing what went wrong.
  • If a "human" error is present (when showing a toast), it is not translated.

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

@qstokkink qstokkink marked this pull request as ready for review September 17, 2024 14:55
@qstokkink qstokkink changed the title WIP: Added explicit error handling READY: Added explicit error handling Sep 17, 2024
@qstokkink qstokkink marked this pull request as draft September 18, 2024 07:25
@qstokkink qstokkink changed the title READY: Added explicit error handling WIP: Added explicit error handling Sep 18, 2024
@qstokkink qstokkink marked this pull request as ready for review September 18, 2024 07:37
@qstokkink qstokkink changed the title WIP: Added explicit error handling READY: Added explicit error handling Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Don't use Axios interceptor for error handling
1 participant