Skip to content

Commit

Permalink
Better generated error reports (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Apr 8, 2023
1 parent 6d4d676 commit 1140512
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
25 changes: 14 additions & 11 deletions src/main/gui/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { lazy } from '../../common/util';
import { OpenArguments } from '../arguments';
import { createMainWindow } from './main-window';

const mdCodeBlock = (code: string): string => {
return `\`\`\`\n${code}\n\`\`\``;
};

const setupErrorHandling = () => {
log.catchErrors({
showDialog: false,
Expand All @@ -18,10 +22,14 @@ const setupErrorHandling = () => {
})
.then((result) => {
if (result.response === 1) {
const stack = error.stack
? `\n${error.stack.replace(String(error), '')}`
: '';

submitIssue!('https://github.com/chaiNNer-org/chaiNNer/issues/new', {
title: `Error report: ${error.message}`,
body: [
`\`\`\`\n${String(error)}\n\`\`\``,
mdCodeBlock(String(error) + stack),
`ChaiNNer: ${String(versions?.app)}`,
`OS: ${String(versions?.os)}`,
].join('\n'),
Expand All @@ -33,15 +41,6 @@ const setupErrorHandling = () => {
.catch((e) => log.error(e));
},
});

process.on('uncaughtException', (error) => {
dialog.showMessageBoxSync({
type: 'error',
title: 'Error in Main process',
message: `Something failed: ${String(error)}`,
});
app.exit(1);
});
};

export const createGuiApp = (args: OpenArguments) => {
Expand All @@ -55,7 +54,11 @@ export const createGuiApp = (args: OpenArguments) => {
}

const createWindow = lazy(() => {
createMainWindow(args).catch((error) => log.error(error));
createMainWindow(args).catch((error) => {
log.error(error);
// rethrow to let the global error handler deal with it
return Promise.reject(error);
});
});

// This method will be called when Electron has finished
Expand Down
4 changes: 2 additions & 2 deletions src/main/gui/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isMac } from '../../common/env';
import { links } from '../../common/links';
import { BrowserWindowWithSafeIpc } from '../../common/safeIpc';
import { openSaveFile } from '../../common/SaveFile';
import { getRootDirSync } from '../platform';
import { getLogsFolder } from '../platform';
import { getCpuInfo, getGpuInfo } from '../systemInfo';

export interface MenuData {
Expand Down Expand Up @@ -233,7 +233,7 @@ export const setMainMenu = ({ mainWindow, menuData, enabled = false }: MainMenuA
{
label: 'Open logs folder',
click: async () => {
await shell.openPath(path.join(getRootDirSync(), 'logs'));
await shell.openPath(getLogsFolder());
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { parseArgs } from './arguments';
import { createCli } from './cli/create';
import { runChainInCli } from './cli/run';
import { createGuiApp } from './gui/create';
import { getRootDirSync } from './platform';
import { getLogsFolder, getRootDirSync } from './platform';

const startApp = () => {
const args = parseArgs(process.argv.slice(app.isPackaged ? 1 : 2));

log.transports.file.resolvePath = (variables) =>
path.join(getRootDirSync(), 'logs', variables.fileName!);
path.join(getLogsFolder(), variables.fileName!);
log.transports.file.level = 'info';

process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
Expand Down
4 changes: 4 additions & 0 deletions src/main/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export const getRootDirSync = lazy((): string => {
const rootDir = isPortable ? currentExecutableDir : app.getPath('userData');
return rootDir;
});

export const getLogsFolder = lazy((): string => {
return path.join(getRootDirSync(), 'logs');
});

0 comments on commit 1140512

Please sign in to comment.