From cd0b818cb82ef98df48f6262790759ddbc70fd04 Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Fri, 19 Jan 2024 00:37:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=B8=8D=E6=8F=90=E7=A4=BA=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 4 +++- noname/util/struct/promise-error-handler/chrome.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/noname/init/index.js b/noname/init/index.js index ddb33575a..974efca80 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -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"); diff --git a/noname/util/struct/promise-error-handler/chrome.js b/noname/util/struct/promise-error-handler/chrome.js index 79b65ac4d..a5120a367 100644 --- a/noname/util/struct/promise-error-handler/chrome.js +++ b/noname/util/struct/promise-error-handler/chrome.js @@ -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', ''].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); } } /* From 2deb535d235103cfbf67bf55127b845c40b12728 Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Fri, 19 Jan 2024 00:40:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=80=E4=B8=AAlog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/noname/init/index.js b/noname/init/index.js index 974efca80..02835a5f8 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -783,7 +783,6 @@ 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, '') : '未知文件'}`;