diff --git a/src/main/first-run.ts b/src/main/first-run.ts index 6ca2aade8..0a5678976 100644 --- a/src/main/first-run.ts +++ b/src/main/first-run.ts @@ -48,8 +48,8 @@ function isFirstRun() { } fs.writeFileSync(configPath, ''); - } catch (error) { - log.error('First run: Unable to write firstRun file', error); + } catch (err) { + log.error('First run: Unable to write firstRun file', err); } return true; diff --git a/src/renderer/hooks/useNotifications.ts b/src/renderer/hooks/useNotifications.ts index e3fe51191..3f4d06d58 100644 --- a/src/renderer/hooks/useNotifications.ts +++ b/src/renderer/hooks/useNotifications.ts @@ -121,7 +121,10 @@ export const useNotifications = (): NotificationsState => { setNotifications(updatedNotifications); setTrayIconColor(updatedNotifications); } catch (err) { - log.error('Error occurred while marking notification as read', err); + log.error( + '[markNotificationsAsRead]: Error occurred while marking notifications as read', + err, + ); } setStatus('success'); @@ -155,7 +158,10 @@ export const useNotifications = (): NotificationsState => { setNotifications(updatedNotifications); setTrayIconColor(updatedNotifications); } catch (err) { - log.error('Error occurred while marking notifications as done', err); + log.error( + '[markNotificationsAsDone]: error occurred while marking notifications as done', + err, + ); } setStatus('success'); @@ -181,7 +187,7 @@ export const useNotifications = (): NotificationsState => { } } catch (err) { log.error( - 'Error occurred while unsubscribing from notification thread', + '[unsubscribeNotification]: error occurred while unsubscribing from notification thread', err, ); } diff --git a/src/renderer/utils/api/client.ts b/src/renderer/utils/api/client.ts index 3615fc3a4..bf39f204f 100644 --- a/src/renderer/utils/api/client.ts +++ b/src/renderer/utils/api/client.ts @@ -217,7 +217,11 @@ export async function getHtmlUrl(url: Link, token: Token): Promise { const response = (await apiRequestAuth(url, 'GET', token)).data; return response.html_url; } catch (err) { - log.error('Error occurred while fetching notification html url', err); + log.error( + '[getHtmlUrl]: error occurred while fetching html url for', + url, + err, + ); } } @@ -268,7 +272,8 @@ export async function getLatestDiscussion( ); } catch (err) { log.error( - 'Error occurred while fetching notification latest discussion', + '[getLatestDiscussion]: failed to fetch latest discussion for notification', + `[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`, err, ); } diff --git a/src/renderer/utils/api/request.ts b/src/renderer/utils/api/request.ts index c4f29e66d..3e0da29e9 100644 --- a/src/renderer/utils/api/request.ts +++ b/src/renderer/utils/api/request.ts @@ -72,9 +72,9 @@ export async function apiRequestAuth( nextUrl = getNextURLFromLinkHeader(response); } - } catch (error) { - log.error('API request failed:', error); - throw error; + } catch (err) { + log.error('[apiRequestAuth]: API request failed:', err); + throw err; } return { diff --git a/src/renderer/utils/auth/utils.ts b/src/renderer/utils/auth/utils.ts index 09f3adda2..b131016f8 100644 --- a/src/renderer/utils/auth/utils.ts +++ b/src/renderer/utils/auth/utils.ts @@ -169,8 +169,12 @@ export async function refreshAccount(account: Account): Promise { account.version = extractHostVersion( res.headers['x-github-enterprise-version'], ); - } catch (error) { - log.error('Failed to refresh account', error); + } catch (err) { + log.error( + '[refreshAccount]: failed to refresh account for user', + account.user.login, + err, + ); } return account; diff --git a/src/renderer/utils/helpers.ts b/src/renderer/utils/helpers.ts index b2e1a4823..2017017e5 100644 --- a/src/renderer/utils/helpers.ts +++ b/src/renderer/utils/helpers.ts @@ -152,9 +152,14 @@ export async function generateGitHubWebUrl( } } catch (err) { log.error( - 'Error occurred while attempting to get a specific notification URL. Will fall back to defaults', + '[generateGitHubWebUrl]: failed to resolve specific notification html url for', + `[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`, err, ); + log.warn( + 'Will fall back to opening repository root url for', + notification.repository.full_name, + ); } url.searchParams.set( diff --git a/src/renderer/utils/notifications.ts b/src/renderer/utils/notifications.ts index c5f2bc7d8..1b0a41b0b 100644 --- a/src/renderer/utils/notifications.ts +++ b/src/renderer/utils/notifications.ts @@ -156,15 +156,15 @@ export async function getAllNotifications( notifications: notifications, error: null, }; - } catch (error) { + } catch (err) { log.error( - 'Error occurred while fetching account notifications', - error, + '[getAllNotifications]: error occurred while fetching account notifications', + err, ); return { account: accountNotifications.account, notifications: [], - error: determineFailureType(error), + error: determineFailureType(err), }; } }), @@ -187,11 +187,13 @@ export async function enrichNotifications( try { additionalSubjectDetails = await getGitifySubjectDetails(notification); - } catch (error) { - log.warn( - `Error occurred while enriching notification ${notification.subject.title} for repository ${notification.repository.full_name}. Continuing with base notification`, - error, + } catch (err) { + log.error( + '[enrichNotifications] failed to enrich notification details for', + `[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`, + err, ); + log.warn('Continuing with base notification details'); } return { diff --git a/src/renderer/utils/subject.test.ts b/src/renderer/utils/subject.test.ts index 9801e59d9..a925915ee 100644 --- a/src/renderer/utils/subject.test.ts +++ b/src/renderer/utils/subject.test.ts @@ -1160,6 +1160,10 @@ describe('renderer/utils/subject.ts', () => { type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1' as Link, }); + const mockRepository = { + full_name: 'gitify-app/notifications-test', + } as Repository; + mockNotification.repository = mockRepository; nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/1') @@ -1168,7 +1172,8 @@ describe('renderer/utils/subject.ts', () => { await getGitifySubjectDetails(mockNotification); expect(logErrorSpy).toHaveBeenCalledWith( - 'Error occurred while fetching details for Issue notification: This issue will throw an error', + '[getGitifySubjectDetails]: failed to fetch details for notification for', + '[Issue]: This issue will throw an error for repository gitify-app/notifications-test', mockError, ); }); diff --git a/src/renderer/utils/subject.ts b/src/renderer/utils/subject.ts index 08d65abcf..223ef60ed 100644 --- a/src/renderer/utils/subject.ts +++ b/src/renderer/utils/subject.ts @@ -50,7 +50,8 @@ export async function getGitifySubjectDetails( } } catch (err) { log.error( - `Error occurred while fetching details for ${notification.subject.type} notification: ${notification.subject.title}`, + '[getGitifySubjectDetails]: failed to fetch details for notification for', + `[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`, err, ); }