mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-29 02:57:25 +00:00
Fix: [ALAS] Error interception in the main thread
This commit is contained in:
parent
cfc5f9455e
commit
67ea7b3ce8
@ -65,6 +65,10 @@ export class CoreService {
|
|||||||
return this.currentService;
|
return this.currentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onError(e: Error | any) {
|
||||||
|
logger.error(`currentServiceIndex:${this.stepIndex}` + (e as unknown as any).toString());
|
||||||
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.stepIndex = 0;
|
this.stepIndex = 0;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ export const createMainWindow = async () => {
|
|||||||
|
|
||||||
browserWindow.webContents.on('preload-error', (event, preloadPath, error) => {
|
browserWindow.webContents.on('preload-error', (event, preloadPath, error) => {
|
||||||
logger.error('------------preload-error------------');
|
logger.error('------------preload-error------------');
|
||||||
logger.error(`event:${JSON.stringify(event)}`);
|
|
||||||
logger.error(`preloadPath:${preloadPath}`);
|
logger.error(`preloadPath:${preloadPath}`);
|
||||||
logger.error(`error:${error}`);
|
logger.error(`error:${error}`);
|
||||||
});
|
});
|
||||||
@ -37,8 +36,7 @@ export const createMainWindow = async () => {
|
|||||||
}
|
}
|
||||||
if (level === 3) {
|
if (level === 3) {
|
||||||
logger.info('------------console-message------------');
|
logger.info('------------console-message------------');
|
||||||
logger.error(`event:${JSON.stringify(event)}`);
|
logger.error(`console-message:${message} \n line:${line} \n sourceId:${sourceId}`);
|
||||||
logger.error(`console-message:${message} line:${line} sourceId:${sourceId}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -4,26 +4,32 @@ import type {CallbackFun} from '/@/coreService';
|
|||||||
import logger from '/@/logger';
|
import logger from '/@/logger';
|
||||||
|
|
||||||
export const createAlas: CallbackFun = async ctx => {
|
export const createAlas: CallbackFun = async ctx => {
|
||||||
const alas = new PyShell(webuiPath, webuiArgs);
|
let alas: PyShell | null = null;
|
||||||
alas.on('error', function (err: string) {
|
try {
|
||||||
|
alas = new PyShell(webuiPath, webuiArgs);
|
||||||
|
} catch (e) {
|
||||||
|
ctx.onError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
alas?.on('error', function (err: string) {
|
||||||
if (!err) return;
|
if (!err) return;
|
||||||
logger.error('alas.error:' + err);
|
logger.error('alas.error:' + err);
|
||||||
ctx.sendLaunchLog(err);
|
ctx.sendLaunchLog(err);
|
||||||
});
|
});
|
||||||
alas.end(function (err: string) {
|
alas?.end(function (err: string) {
|
||||||
if (!err) return;
|
if (!err) return;
|
||||||
logger.info('alas.end:' + err);
|
logger.info('alas.end:' + err);
|
||||||
ctx.sendLaunchLog(err);
|
ctx.sendLaunchLog(err);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
alas.on('stdout', function (message) {
|
alas?.on('stdout', function (message) {
|
||||||
ctx.sendLaunchLog(message);
|
ctx.sendLaunchLog(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
alas.on('message', function (message) {
|
alas?.on('message', function (message) {
|
||||||
ctx.sendLaunchLog(message);
|
ctx.sendLaunchLog(message);
|
||||||
});
|
});
|
||||||
alas.on('stderr', function (message: string) {
|
alas?.on('stderr', function (message: string) {
|
||||||
ctx.sendLaunchLog(message);
|
ctx.sendLaunchLog(message);
|
||||||
/**
|
/**
|
||||||
* Receive logs, judge if Alas is ready
|
* 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): `
|
* `[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')) {
|
if (message.includes('Application startup complete') || message.includes('bind on address')) {
|
||||||
alas.removeAllListeners('stderr');
|
alas?.removeAllListeners('stderr');
|
||||||
alas.removeAllListeners('message');
|
alas?.removeAllListeners('message');
|
||||||
alas.removeAllListeners('stdout');
|
alas?.removeAllListeners('stdout');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
alas?.on('pythonError', err => {
|
||||||
|
ctx.onError('alas pythonError:' + err);
|
||||||
|
});
|
||||||
return alas;
|
return alas;
|
||||||
};
|
};
|
||||||
|
@ -7,8 +7,14 @@ export const createInstaller: CallbackFun = async (ctx, next) => {
|
|||||||
if (process.argv.includes(ALAS_RELAUNCH_ARGV)) {
|
if (process.argv.includes(ALAS_RELAUNCH_ARGV)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const installer = new PyShell(installerPath, installerArgs);
|
let installer: PyShell | null = null;
|
||||||
installer.on('error', function (err: string) {
|
try {
|
||||||
|
installer = new PyShell(installerPath, installerArgs);
|
||||||
|
} catch (err) {
|
||||||
|
ctx.onError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
installer?.on('error', function (err: string) {
|
||||||
if (!err) return;
|
if (!err) return;
|
||||||
logger.error('installer.error:' + err);
|
logger.error('installer.error:' + err);
|
||||||
ctx.sendLaunchLog(err);
|
ctx.sendLaunchLog(err);
|
||||||
@ -17,7 +23,7 @@ export const createInstaller: CallbackFun = async (ctx, next) => {
|
|||||||
if (!err) return;
|
if (!err) return;
|
||||||
logger.info('installer.end:' + err);
|
logger.info('installer.end:' + err);
|
||||||
ctx.sendLaunchLog(err);
|
ctx.sendLaunchLog(err);
|
||||||
throw err;
|
// throw err;
|
||||||
});
|
});
|
||||||
installer?.on('stdout', function (message) {
|
installer?.on('stdout', function (message) {
|
||||||
ctx.sendLaunchLog(message);
|
ctx.sendLaunchLog(message);
|
||||||
@ -28,5 +34,10 @@ export const createInstaller: CallbackFun = async (ctx, next) => {
|
|||||||
installer?.on('stderr', function (message: string) {
|
installer?.on('stderr', function (message: string) {
|
||||||
ctx.sendLaunchLog(message);
|
ctx.sendLaunchLog(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
installer?.on('pythonError', err => {
|
||||||
|
ctx.onError('alas pythonError :' + err);
|
||||||
|
});
|
||||||
|
|
||||||
return installer;
|
return installer;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user