修复技能报错不提示技能代码的bug

This commit is contained in:
nonameShijian 2024-01-19 00:37:31 +08:00
parent 842835c521
commit cd0b818cb8
2 changed files with 12 additions and 6 deletions

View File

@ -783,6 +783,7 @@ async function setOnError() {
});
window.onerror = function (msg, src, line, column, err) {
console.log([...arguments]);
if (promiseErrorHandler.onErrorPrepare) promiseErrorHandler.onErrorPrepare();
const winPath = window.__dirname ? ('file:///' + (__dirname.replace(new RegExp('\\\\', 'g'), '/') + '/')) : '';
let str = `错误文件: ${typeof src == 'string' ? decodeURI(src).replace(lib.assetURL, '').replace(winPath, '') : '未知文件'}`;
@ -861,7 +862,8 @@ async function setOnError() {
}
}
//解析parsex里的content fun内容(通常是技能content)
else if (err && err.stack && err.stack.split('\n')[1].trim().startsWith('at Object.eval [as content]')) {
// @ts-ignore
else if (err && err.stack && ['at Object.eval [as content]', 'at Proxy.content'].some(str => err.stack.split('\n')[1].trim().startsWith(str))) {
const codes = _status.event.content;
if (typeof codes == 'function') {
const lines = codes.toString().split("\n");

View File

@ -98,12 +98,12 @@ export class ChromePromiseErrorHandler {
let fileName = void 0;
/**
* @type {string | undefined}
* @type {number | undefined}
*/
let line = void 0;
/**
* @type {string | undefined}
* @type {number | undefined}
*/
let column = void 0;
@ -119,8 +119,8 @@ export class ChromePromiseErrorHandler {
const locationParts = extractLocation(location ? location[1] : formatedLine);
fileName = ['eval', '<anonymous>'].includes(locationParts[0]) ? void 0 : locationParts[0];
line = locationParts[1];
column = locationParts[2];
line = Number(locationParts[1]);
column = Number(locationParts[2]);
break;
}
@ -130,7 +130,11 @@ export class ChromePromiseErrorHandler {
// 反之我们只能不考虑报错文件信息直接调用onerror
else {
// @ts-ignore
window.onerror(error.message, void 0, void 0, void 0, error);
let [_, src = void 0, line = void 0, column = void 0] = /at\s+.*\s+\((.*):(\d*):(\d*)\)/i.exec(error.stack.split('\n')[1])
if (typeof line == 'string') line = Number(line);
if (typeof column == 'string') column = Number(column);
// @ts-ignore
window.onerror(error.message, src, line, column, error);
}
}
/*