diff --git a/.eslintignore b/.eslintignore index 557a34e10..c7e7f96dd 100644 --- a/.eslintignore +++ b/.eslintignore @@ -666,6 +666,7 @@ packages/lib/import-enex.js packages/lib/initLib.js packages/lib/locale.test.js packages/lib/locale.js +packages/lib/makeDiscourseDebugUrl.test.js packages/lib/makeDiscourseDebugUrl.js packages/lib/markdownUtils.test.js packages/lib/markdownUtils.js diff --git a/.gitignore b/.gitignore index d7990a4b7..a54ec9875 100644 --- a/.gitignore +++ b/.gitignore @@ -646,6 +646,7 @@ packages/lib/import-enex.js packages/lib/initLib.js packages/lib/locale.test.js packages/lib/locale.js +packages/lib/makeDiscourseDebugUrl.test.js packages/lib/makeDiscourseDebugUrl.js packages/lib/markdownUtils.test.js packages/lib/markdownUtils.js diff --git a/packages/lib/makeDiscourseDebugUrl.test.ts b/packages/lib/makeDiscourseDebugUrl.test.ts new file mode 100644 index 000000000..febaecf20 --- /dev/null +++ b/packages/lib/makeDiscourseDebugUrl.test.ts @@ -0,0 +1,18 @@ +import { renderErrorBlock } from './makeDiscourseDebugUrl'; + +describe('makeDiscourseDebugUrl', () => { + + it('should render errors', () => { + const errors = [ + new Error('First'), + new Error('Second'), + 'Just a plain string', + ]; + + const actual = renderErrorBlock(errors); + expect(actual.startsWith('```\nError: First\n at Object')).toBe(true); + expect(actual.includes(')\n\nError: Second\n at Object')).toBe(true); + expect(actual.endsWith(')\n\nJust a plain string\n```')).toBe(true); + }); + +}); diff --git a/packages/lib/makeDiscourseDebugUrl.ts b/packages/lib/makeDiscourseDebugUrl.ts index 2d9769e58..4c33665d2 100644 --- a/packages/lib/makeDiscourseDebugUrl.ts +++ b/packages/lib/makeDiscourseDebugUrl.ts @@ -2,9 +2,12 @@ import { PluginSettings } from './services/plugins/PluginService'; import type PluginService from './services/plugins/PluginService'; import versionInfo, { PackageInfo } from './versionInfo'; -const renderErrorBlock = (errors: any[]): string => { +export const renderErrorBlock = (errors: (string | Error)[]): string => { if (!errors.length) return ''; - return `\`\`\`\n${errors.map(e => typeof e === 'string' ? e.trim() : e.message.trim())}\n\`\`\``; + return `\`\`\`\n${errors.map(e => { + if (typeof e === 'string') return e.trim(); + return e.message.trim() + e.stack ? `\n${e.stack}` : ''; + }).map(l => l.trim()).join('\n\n')}\n\`\`\``; }; const getOsName = (platform: typeof process.platform) => { @@ -15,7 +18,7 @@ const getOsName = (platform: typeof process.platform) => { return ''; }; -export default (title: string, body: string, errors: any[], packageInfo: PackageInfo, pluginService: PluginService, pluginSettings: PluginSettings) => { +export default (title: string, body: string, errors: (string | Error)[], packageInfo: PackageInfo, pluginService: PluginService, pluginSettings: PluginSettings) => { const v = versionInfo(packageInfo, pluginService.enabledPlugins(pluginSettings)); const errorBlock = renderErrorBlock(errors);