1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Desktop: Include more information when auto-generating import error report

This commit is contained in:
Laurent Cozic 2023-12-16 13:12:00 +00:00
parent a2ded180cb
commit 17c25b72f0
4 changed files with 26 additions and 3 deletions

View File

@ -666,6 +666,7 @@ packages/lib/import-enex.js
packages/lib/initLib.js packages/lib/initLib.js
packages/lib/locale.test.js packages/lib/locale.test.js
packages/lib/locale.js packages/lib/locale.js
packages/lib/makeDiscourseDebugUrl.test.js
packages/lib/makeDiscourseDebugUrl.js packages/lib/makeDiscourseDebugUrl.js
packages/lib/markdownUtils.test.js packages/lib/markdownUtils.test.js
packages/lib/markdownUtils.js packages/lib/markdownUtils.js

1
.gitignore vendored
View File

@ -646,6 +646,7 @@ packages/lib/import-enex.js
packages/lib/initLib.js packages/lib/initLib.js
packages/lib/locale.test.js packages/lib/locale.test.js
packages/lib/locale.js packages/lib/locale.js
packages/lib/makeDiscourseDebugUrl.test.js
packages/lib/makeDiscourseDebugUrl.js packages/lib/makeDiscourseDebugUrl.js
packages/lib/markdownUtils.test.js packages/lib/markdownUtils.test.js
packages/lib/markdownUtils.js packages/lib/markdownUtils.js

View File

@ -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);
});
});

View File

@ -2,9 +2,12 @@ import { PluginSettings } from './services/plugins/PluginService';
import type PluginService from './services/plugins/PluginService'; import type PluginService from './services/plugins/PluginService';
import versionInfo, { PackageInfo } from './versionInfo'; import versionInfo, { PackageInfo } from './versionInfo';
const renderErrorBlock = (errors: any[]): string => { export const renderErrorBlock = (errors: (string | Error)[]): string => {
if (!errors.length) return ''; 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) => { const getOsName = (platform: typeof process.platform) => {
@ -15,7 +18,7 @@ const getOsName = (platform: typeof process.platform) => {
return ''; 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 v = versionInfo(packageInfo, pluginService.enabledPlugins(pluginSettings));
const errorBlock = renderErrorBlock(errors); const errorBlock = renderErrorBlock(errors);