Skip to content

Commit

Permalink
Fix: [ALAS] Error interception in the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
LmeSzinc committed Sep 25, 2023
1 parent cfc5f94 commit 67ea7b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
4 changes: 4 additions & 0 deletions webapp/packages/main/src/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class CoreService {
return this.currentService;
}

onError(e: Error | any) {
logger.error(`currentServiceIndex:${this.stepIndex}` + (e as unknown as any).toString());
}

reset() {
this.stepIndex = 0;
}
Expand Down
4 changes: 1 addition & 3 deletions webapp/packages/main/src/createMainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const createMainWindow = async () => {

browserWindow.webContents.on('preload-error', (event, preloadPath, error) => {
logger.error('------------preload-error------------');
logger.error(`event:${JSON.stringify(event)}`);
logger.error(`preloadPath:${preloadPath}`);
logger.error(`error:${error}`);
});
Expand All @@ -37,8 +36,7 @@ export const createMainWindow = async () => {
}
if (level === 3) {
logger.info('------------console-message------------');
logger.error(`event:${JSON.stringify(event)}`);
logger.error(`console-message:${message} line:${line} sourceId:${sourceId}`);
logger.error(`console-message:${message} \n line:${line} \n sourceId:${sourceId}`);
return;
}
});
Expand Down
32 changes: 21 additions & 11 deletions webapp/packages/main/src/serviceLogic/createAlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ import type {CallbackFun} from '/@/coreService';
import logger from '/@/logger';

export const createAlas: CallbackFun = async ctx => {
const alas = new PyShell(webuiPath, webuiArgs);
alas.on('error', function (err: string) {
if(!err) return;
let alas: PyShell | null = null;
try {
alas = new PyShell(webuiPath, webuiArgs);
} catch (e) {
ctx.onError(e);
}

alas?.on('error', function (err: string) {
if (!err) return;
logger.error('alas.error:' + err);
ctx.sendLaunchLog(err);
});
alas.end(function (err: string) {
if(!err) return;
alas?.end(function (err: string) {
if (!err) return;
logger.info('alas.end:' + err);
ctx.sendLaunchLog(err);
throw err;
});
alas.on('stdout', function (message) {
alas?.on('stdout', function (message) {
ctx.sendLaunchLog(message);
});

alas.on('message', function (message) {
alas?.on('message', function (message) {
ctx.sendLaunchLog(message);
});
alas.on('stderr', function (message: string) {
alas?.on('stderr', function (message: string) {
ctx.sendLaunchLog(message);
/**
* Receive logs, judge if Alas is ready
Expand All @@ -33,10 +39,14 @@ export const createAlas: CallbackFun = async ctx => {
* `[Errno 10048] error while attempting to bind on address ('0.0.0.0', 22267): `
*/
if (message.includes('Application startup complete') || message.includes('bind on address')) {
alas.removeAllListeners('stderr');
alas.removeAllListeners('message');
alas.removeAllListeners('stdout');
alas?.removeAllListeners('stderr');
alas?.removeAllListeners('message');
alas?.removeAllListeners('stdout');
}
});

alas?.on('pythonError', err => {
ctx.onError('alas pythonError:' + err);
});
return alas;
};
21 changes: 16 additions & 5 deletions webapp/packages/main/src/serviceLogic/createInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ export const createInstaller: CallbackFun = async (ctx, next) => {
if (process.argv.includes(ALAS_RELAUNCH_ARGV)) {
return next();
}
const installer = new PyShell(installerPath, installerArgs);
installer.on('error', function (err: string) {
if(!err) return;
let installer: PyShell | null = null;
try {
installer = new PyShell(installerPath, installerArgs);
} catch (err) {
ctx.onError(err);
}

installer?.on('error', function (err: string) {
if (!err) return;
logger.error('installer.error:' + err);
ctx.sendLaunchLog(err);
});
installer?.end(function (err: string) {
if(!err) return;
if (!err) return;
logger.info('installer.end:' + err);
ctx.sendLaunchLog(err);
throw err;
// throw err;
});
installer?.on('stdout', function (message) {
ctx.sendLaunchLog(message);
Expand All @@ -28,5 +34,10 @@ export const createInstaller: CallbackFun = async (ctx, next) => {
installer?.on('stderr', function (message: string) {
ctx.sendLaunchLog(message);
});

installer?.on('pythonError', err => {
ctx.onError('alas pythonError :' + err);
});

return installer;
};

0 comments on commit 67ea7b3

Please sign in to comment.