MCPcopy Index your code
hub / github.com/refined-github/refined-github / logError

Function logError

source/helpers/errors.ts:34–86  ·  view source on GitHub ↗
(error: Error)

Source from the content-addressed store, hash-verified

32const loggedStacks = new Set<string>();
33
34export function logError(error: Error): void {
35 if (!isLoggingEnabled) {
36 return;
37 }
38
39 const {message, stack} = error;
40
41 if (message === 'Extension context invalidated.') {
42 warnOnce('ℹ️ Refined GitHub has been disabled or updated. Reload the page');
43 return;
44 }
45
46 // Avoid duplicate errors
47 if (loggedStacks.has(stack!)) {
48 return;
49 }
50
51 loggedStacks.add(stack!);
52
53 const id = parseFeatureNameFromStack(stack);
54 if (message.endsWith(fineGrainedTokenSuggestion)) {
55 console.log('ℹ️', id, '→', message.replace(fineGrainedTokenSuggestion, preferredMessage));
56 return;
57 }
58
59 if (message.includes('token')) {
60 console.log('ℹ️ Refined GitHub →', message, '→', id);
61 return;
62 }
63
64 const searchIssueUrl = new URL('https://github.com/refined-github/refined-github/issues');
65 searchIssueUrl.searchParams.set('q', `is:issue state:open label:bug ${id ?? message}`);
66
67 const newIssueUrl = new URL('https://github.com/refined-github/refined-github/issues/new');
68 newIssueUrl.searchParams.set('template', '1_bug_report.yml');
69 newIssueUrl.searchParams.set('title', id ? `\`${id}\`: ${message}` : message);
70 newIssueUrl.searchParams.set('repro', location.href);
71 newIssueUrl.searchParams.set(
72 'description',
73 [
74 '```',
75 stack!.trim(),
76 '```',
77 ].join('\n'),
78 );
79
80 // Don't change this to `throw Error` because Firefox doesn't show extensions' errors in the console
81 console.group(`❌ Refined GitHub: ${id ?? 'global'}`); // Safari supports only one parameter
82 console.log(`📕 ${version} ${isEnterprise() ? 'GHE →' : '→'}`, error); // One parameter improves Safari formatting
83 console.log('🔍 Search issue', searchIssueUrl.href);
84 console.log('🚨 Report issue', newIssueUrl.href);
85 console.groupEnd();
86}
87
88export function catchErrors(): void {
89 globalThis.addEventListener('error', event => {

Callers 2

catchErrorsFunction · 0.85
linkifyIssueFunction · 0.85

Calls 5

isEnterpriseFunction · 0.85
replaceMethod · 0.80
includesMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected