Skip to content

Commit 5c3f303

Browse files
authored
refactor(logging): improve details in logs (#1681)
Signed-off-by: Adam Setch <[email protected]>
1 parent 1284c05 commit 5c3f303

File tree

9 files changed

+51
-23
lines changed

9 files changed

+51
-23
lines changed

src/main/first-run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function isFirstRun() {
4848
}
4949

5050
fs.writeFileSync(configPath, '');
51-
} catch (error) {
52-
log.error('First run: Unable to write firstRun file', error);
51+
} catch (err) {
52+
log.error('First run: Unable to write firstRun file', err);
5353
}
5454

5555
return true;

src/renderer/hooks/useNotifications.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export const useNotifications = (): NotificationsState => {
121121
setNotifications(updatedNotifications);
122122
setTrayIconColor(updatedNotifications);
123123
} catch (err) {
124-
log.error('Error occurred while marking notification as read', err);
124+
log.error(
125+
'[markNotificationsAsRead]: Error occurred while marking notifications as read',
126+
err,
127+
);
125128
}
126129

127130
setStatus('success');
@@ -155,7 +158,10 @@ export const useNotifications = (): NotificationsState => {
155158
setNotifications(updatedNotifications);
156159
setTrayIconColor(updatedNotifications);
157160
} catch (err) {
158-
log.error('Error occurred while marking notifications as done', err);
161+
log.error(
162+
'[markNotificationsAsDone]: error occurred while marking notifications as done',
163+
err,
164+
);
159165
}
160166

161167
setStatus('success');
@@ -181,7 +187,7 @@ export const useNotifications = (): NotificationsState => {
181187
}
182188
} catch (err) {
183189
log.error(
184-
'Error occurred while unsubscribing from notification thread',
190+
'[unsubscribeNotification]: error occurred while unsubscribing from notification thread',
185191
err,
186192
);
187193
}

src/renderer/utils/api/client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
217217
const response = (await apiRequestAuth(url, 'GET', token)).data;
218218
return response.html_url;
219219
} catch (err) {
220-
log.error('Error occurred while fetching notification html url', err);
220+
log.error(
221+
'[getHtmlUrl]: error occurred while fetching html url for',
222+
url,
223+
err,
224+
);
221225
}
222226
}
223227

@@ -268,7 +272,8 @@ export async function getLatestDiscussion(
268272
);
269273
} catch (err) {
270274
log.error(
271-
'Error occurred while fetching notification latest discussion',
275+
'[getLatestDiscussion]: failed to fetch latest discussion for notification',
276+
`[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`,
272277
err,
273278
);
274279
}

src/renderer/utils/api/request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export async function apiRequestAuth(
7272

7373
nextUrl = getNextURLFromLinkHeader(response);
7474
}
75-
} catch (error) {
76-
log.error('API request failed:', error);
77-
throw error;
75+
} catch (err) {
76+
log.error('[apiRequestAuth]: API request failed:', err);
77+
throw err;
7878
}
7979

8080
return {

src/renderer/utils/auth/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,12 @@ export async function refreshAccount(account: Account): Promise<Account> {
169169
account.version = extractHostVersion(
170170
res.headers['x-github-enterprise-version'],
171171
);
172-
} catch (error) {
173-
log.error('Failed to refresh account', error);
172+
} catch (err) {
173+
log.error(
174+
'[refreshAccount]: failed to refresh account for user',
175+
account.user.login,
176+
err,
177+
);
174178
}
175179

176180
return account;

src/renderer/utils/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ export async function generateGitHubWebUrl(
152152
}
153153
} catch (err) {
154154
log.error(
155-
'Error occurred while attempting to get a specific notification URL. Will fall back to defaults',
155+
'[generateGitHubWebUrl]: failed to resolve specific notification html url for',
156+
`[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`,
156157
err,
157158
);
159+
log.warn(
160+
'Will fall back to opening repository root url for',
161+
notification.repository.full_name,
162+
);
158163
}
159164

160165
url.searchParams.set(

src/renderer/utils/notifications.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ export async function getAllNotifications(
156156
notifications: notifications,
157157
error: null,
158158
};
159-
} catch (error) {
159+
} catch (err) {
160160
log.error(
161-
'Error occurred while fetching account notifications',
162-
error,
161+
'[getAllNotifications]: error occurred while fetching account notifications',
162+
err,
163163
);
164164
return {
165165
account: accountNotifications.account,
166166
notifications: [],
167-
error: determineFailureType(error),
167+
error: determineFailureType(err),
168168
};
169169
}
170170
}),
@@ -187,11 +187,13 @@ export async function enrichNotifications(
187187

188188
try {
189189
additionalSubjectDetails = await getGitifySubjectDetails(notification);
190-
} catch (error) {
191-
log.warn(
192-
`Error occurred while enriching notification ${notification.subject.title} for repository ${notification.repository.full_name}. Continuing with base notification`,
193-
error,
190+
} catch (err) {
191+
log.error(
192+
'[enrichNotifications] failed to enrich notification details for',
193+
`[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`,
194+
err,
194195
);
196+
log.warn('Continuing with base notification details');
195197
}
196198

197199
return {

src/renderer/utils/subject.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,10 @@ describe('renderer/utils/subject.ts', () => {
11601160
type: 'Issue',
11611161
url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1' as Link,
11621162
});
1163+
const mockRepository = {
1164+
full_name: 'gitify-app/notifications-test',
1165+
} as Repository;
1166+
mockNotification.repository = mockRepository;
11631167

11641168
nock('https://api.github.com')
11651169
.get('/repos/gitify-app/notifications-test/issues/1')
@@ -1168,7 +1172,8 @@ describe('renderer/utils/subject.ts', () => {
11681172
await getGitifySubjectDetails(mockNotification);
11691173

11701174
expect(logErrorSpy).toHaveBeenCalledWith(
1171-
'Error occurred while fetching details for Issue notification: This issue will throw an error',
1175+
'[getGitifySubjectDetails]: failed to fetch details for notification for',
1176+
'[Issue]: This issue will throw an error for repository gitify-app/notifications-test',
11721177
mockError,
11731178
);
11741179
});

src/renderer/utils/subject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export async function getGitifySubjectDetails(
5050
}
5151
} catch (err) {
5252
log.error(
53-
`Error occurred while fetching details for ${notification.subject.type} notification: ${notification.subject.title}`,
53+
'[getGitifySubjectDetails]: failed to fetch details for notification for',
54+
`[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`,
5455
err,
5556
);
5657
}

0 commit comments

Comments
 (0)