(title: string, error: Error, type: ErrorType)
| 39 | } |
| 40 | |
| 41 | const handleError = async(title: string, error: Error, type: ErrorType): Promise<void> => { |
| 42 | const { message, stack } = error |
| 43 | |
| 44 | // Write error into file |
| 45 | if (type === 'main') { |
| 46 | logger(exceptionToString(error, type)) |
| 47 | } |
| 48 | |
| 49 | if (EXIT_ON_ERROR) { |
| 50 | console.log(t('error.terminatedDueToError')) |
| 51 | process.exit(1) |
| 52 | // eslint, don't lie to me, the return statement is important! |
| 53 | return |
| 54 | } else if ( |
| 55 | !SHOW_ERROR_DIALOG || |
| 56 | ((global as unknown as { MARKTEXT_IS_STABLE?: boolean }).MARKTEXT_IS_STABLE && |
| 57 | type === 'renderer') |
| 58 | ) { |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | // show error dialog |
| 63 | if (app.isReady()) { |
| 64 | // Blocking message box |
| 65 | const { response } = await dialog.showMessageBox({ |
| 66 | type: 'error', |
| 67 | buttons: [t('common.ok'), t('error.copyError'), t('error.report')], |
| 68 | defaultId: 0, |
| 69 | noLink: true, |
| 70 | message: title, |
| 71 | detail: stack |
| 72 | }) |
| 73 | |
| 74 | switch (response) { |
| 75 | case 1: { |
| 76 | clipboard.writeText(`${title}\n${stack}`) |
| 77 | break |
| 78 | } |
| 79 | case 2: { |
| 80 | const issueTitle = message ? t('error.unexpectedErrorWithMessage', { message }) : title |
| 81 | createAndOpenGitHubIssueUrl( |
| 82 | issueTitle, |
| 83 | `### Description |
| 84 | |
| 85 | ${title}. |
| 86 | |
| 87 | ### Minimal Reprouducible Markdown Example (or Steps) |
| 88 | |
| 89 | <Add steps or a markdown example to reproduce the problem.> |
| 90 | |
| 91 | ### Stack Trace |
| 92 | |
| 93 | \`\`\`\n${stack}\n\`\`\` |
| 94 | |
| 95 | ### Version |
| 96 | |
| 97 | MarkText: ${MARKTEXT_VERSION_STRING} |
| 98 | Operating system: ${getOSInformation()}` |
no test coverage detected