diff options
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r-- | source/libs/utils.ts | 14 |
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 => { |