summaryrefslogtreecommitdiff
path: root/source/libs/utils.ts
diff options
context:
space:
mode:
authorGravatar Federico Brigante <github@bfred.it> 2020-01-21 03:25:57 +0700
committerGravatar GitHub <noreply@github.com> 2020-01-21 03:25:57 +0700
commit42fa0d72e3a2328cebf4044691949fd918dcfef4 (patch)
tree968524de6f319a171f5a48253f9c5e1141f985f3 /source/libs/utils.ts
parent22764b8ba0475cef2a87adf134acb828852daaa8 (diff)
downloadrefined-github-42fa0d72e3a2328cebf4044691949fd918dcfef4.tar.gz
refined-github-42fa0d72e3a2328cebf4044691949fd918dcfef4.tar.zst
refined-github-42fa0d72e3a2328cebf4044691949fd918dcfef4.zip
Meta: Add error logger that helps user search/report issues (#2708)
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r--source/libs/utils.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/libs/utils.ts b/source/libs/utils.ts
index 85886c97..b8efa1b6 100644
--- a/source/libs/utils.ts
+++ b/source/libs/utils.ts
@@ -1,7 +1,21 @@
import select from 'select-dom';
import onetime from 'onetime';
+import stripIndent from 'strip-indent';
import {isRepo, isPR, isIssue} from './page-detect';
+export function logError(featureName: typeof __featureName__, message: string, ...extras: unknown[]): void {
+ // Don't change this to `throw Error` because Firefox doesn't show extensions' errors in the console.
+ // Use `return` after calling this function.
+ console.error(`❌ Refined GitHub: feature \`${featureName}\`\n\n${message}`, ...extras, stripIndent(`
+
+ Search for open issues:
+ https://github.com/sindresorhus/refined-github/issues?q=is%3Aissue+${encodeURIComponent(message)}
+
+ or open a new one:
+ https://github.com/sindresorhus/refined-github/issues/new?labels=bug&template=bug_report.md&title=${encodeURIComponent(`\`${featureName}\`: ${message}`)}
+ `));
+}
+
export const getUsername = onetime(() => select('meta[name="user-login"]')!.getAttribute('content')!);
export const getDiscussionNumber = (): string | undefined => {