Fix: [ALAS] Error interception in the main thread

This commit is contained in:
LmeSzinc 2023-09-25 23:30:16 +08:00
parent cfc5f9455e
commit 67ea7b3ce8
4 changed files with 42 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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