提交 baef92ee 编写于 作者: D DCloud_LXH

chore: uni-stacktracey

上级 c140fab2
const {
stacktracey,
uniStracktraceyPreset,
utsStracktraceyPreset,
} = require('../dist/uni-stacktracey.cjs.js')
const utsErrorMsg = `Appid: __UNI__E070870
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestComponent.kt: (68, 9): Unresolved reference: hello
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (30, 9): Unresolved reference: hello
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s`
const uniErrorMsg = `ReferenceError: Sentry is not defined
at Proxy.throwError(/vue3/assets/pages-index-index.4077a069.js:1:295)
at e(/vue3/assets/index.2be9343a.js:1:52317)
at Ue(/vue3/assets/index.2be9343a.js:1:16271)
at He(/vue3/assets/index.2be9343a.js:1:16349)
at HTMLElement.n(/vue3/assets/index.2be9343a.js:1:51834)
at HTMLElement.o(/vue3/assets/index.2be9343a.js:21:60087)`
describe('uni-stacktracey', () => {
test('uniStracktraceyPreset', () => {
stacktracey(uniErrorMsg, {
preset: uniStracktraceyPreset({
base: 'https://7463-tcb-uzyfn59tqxjxtnbab2e2c-5ba40b-1303909289.tcb.qcloud.la',
platform: 'h5',
version: '1.0.0',
}),
}).then((res: string) => {
expect(res).toEqual(`ReferenceError: Sentry is not defined
at Proxy.throwError(/vue3/assets/pages-index-index.4077a069.js:1
at e(/vue3/assets/index.2be9343a.js:1
at Ue(/vue3/assets/index.2be9343a.js:1
at He(/vue3/assets/index.2be9343a.js:1
at HTMLElement.n(/vue3/assets/index.2be9343a.js:1
at HTMLElement.o(/vue3/assets/index.2be9343a.js:21 `)
})
})
test('uniStracktraceyPreset', () => {
stacktracey(utsErrorMsg, {
preset: utsStracktraceyPreset({
base: '/usr/fxy/poroject/test/.sourcemap/src/',
sourceRoot:
'/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/',
}),
}).then((res: string) => {
expect(res).toEqual(`Appid: __UNI__E070870
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestComponent.kt: (68, 9): Unresolved reference: hello
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (30, 9): Unresolved reference: hello
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s`)
})
})
})
......@@ -73,16 +73,14 @@ function getSourceMapContent(sourcemapUrl) {
(sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
try {
if (/^[a-z]+:/i.test(sourcemapUrl)) {
/* uni
.request(sourcemapUrl)
.then((res) => {
console.log('sourcemapUrl :>> ', sourcemapUrl)
sourcemapCatch[sourcemapUrl] = res.data
resolve(sourcemapCatch[sourcemapUrl])
})
.catch((_) => {
resolve('')
}) */
uni.request({
url: sourcemapUrl,
success: (res) => {
console.log('sourcemapUrl :>> ', sourcemapUrl);
sourcemapCatch[sourcemapUrl] = res.data;
resolve(sourcemapCatch[sourcemapUrl]);
},
});
}
else {
sourcemapCatch[sourcemapUrl] = fs__default["default"].readFileSync(sourcemapUrl, 'utf-8');
......@@ -132,18 +130,18 @@ function uniStracktraceyPreset(opts) {
},
asTableStacktrace({ maxColumnWidths, stacktrace } = { stacktrace: '' }) {
const errorName = stacktrace.split('\n')[0];
return errorName.indexOf('at') === -1
? `${errorName}\n`
: '' + (stack.asTable ? stack.asTable({ maxColumnWidths }) : '');
return ((errorName.indexOf('at') === -1 ? `${errorName}\n` : '') +
(stack.asTable ? stack.asTable({ maxColumnWidths }) : ''));
},
};
}
function utsStracktraceyPreset(opts) {
let stack;
let errStack = [];
return {
parseSourceMapUrl(file, fileName) {
// 根据 base,filename 组合 sourceMapUrl
return `${opts.base}/${fileName}.map`;
return `${opts.base}${file.replace(opts.sourceRoot, '')}.map`;
},
getSourceMapContent(file, fileName) {
// 根据 base,filename 组合 sourceMapUrl
......@@ -152,27 +150,29 @@ function utsStracktraceyPreset(opts) {
parseStacktrace(str) {
const lines = (str || '').split('\n');
const entries = lines
.map((line) => {
.map((line, index) => {
line = line.trim();
let callee, fileLineColumn = [], planA, planB;
if ((planA = line.match(/e: \[(.+)\](.+): (.+)/))) {
callee = planA[1];
fileLineColumn = (planA[2].match(/(.+):.*\((\d+).+?(\d+)\)/) || []).slice(1);
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
errStack.push('%StacktraceyItem%');
callee = 'e: ';
fileLineColumn = (planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []).slice(1);
}
else {
errStack.push(line);
return undefined;
}
const fileName = fileLineColumn[0]
? (planB = fileLineColumn[0].match(/(\/.*)*\/(.+)/) || [])[2] || ''
const fileName = planA[1]
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
: '';
return {
beforeParse: line,
callee: callee || '',
index: false,
native: false,
file: nixSlashes(fileLineColumn[0] || ''),
line: parseInt(fileLineColumn[1] || '', 10) || undefined,
column: parseInt(fileLineColumn[2] || '', 10) || undefined,
file: nixSlashes(planA[1] || ''),
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
fileName,
fileShort: planB ? planB[1] : '',
errMsg: planA[3] || '',
......@@ -187,14 +187,16 @@ function utsStracktraceyPreset(opts) {
});
},
asTableStacktrace({ stacktrace } = { stacktrace: '' }) {
const stacktraceSplit = stacktrace.split('\n');
const errorName = stacktraceSplit[0];
const errorMsg = stacktraceSplit.pop();
return ((errorName.indexOf('e:') === -1 ? `${errorName}\n` : '') +
(stack.items
.map((item) => `e: [${item.callee}]${item.fileShort}/${item.fileName}: (${item.line}, ${item.column}): ${item.errMsg}`)
.join('\n') +
(errorMsg ? `\n\n${errorMsg}` : '')));
return errStack
.map((item) => {
if (item === '%StacktraceyItem%') {
const _stack = stack.items.shift();
if (_stack)
return `${_stack.callee}${_stack.fileShort}/${_stack.fileName}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`;
}
return item;
})
.join('\n');
},
};
}
......
......@@ -23,5 +23,7 @@
"stacktracey": "^2.1.8",
"source-map": "^0.7.3"
},
"devDependencies": {}
"devDependencies": {
"@dcloudio/types": "^2.6.6"
}
}
......@@ -120,16 +120,14 @@ function getSourceMapContent(sourcemapUrl: string) {
(sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
try {
if (/^[a-z]+:/i.test(sourcemapUrl)) {
/* uni
.request(sourcemapUrl)
.then((res) => {
uni.request({
url: sourcemapUrl,
success: (res) => {
console.log('sourcemapUrl :>> ', sourcemapUrl)
sourcemapCatch[sourcemapUrl] = res.data
sourcemapCatch[sourcemapUrl] = res.data as string
resolve(sourcemapCatch[sourcemapUrl])
},
})
.catch((_) => {
resolve('')
}) */
} else {
sourcemapCatch[sourcemapUrl] = fs.readFileSync(
sourcemapUrl,
......@@ -212,9 +210,10 @@ export function uniStracktraceyPreset(
},
asTableStacktrace({ maxColumnWidths, stacktrace } = { stacktrace: '' }) {
const errorName = stacktrace.split('\n')[0]
return errorName.indexOf('at') === -1
? `${errorName}\n`
: '' + (stack.asTable ? stack.asTable({ maxColumnWidths }) : '')
return (
(errorName.indexOf('at') === -1 ? `${errorName}\n` : '') +
(stack.asTable ? stack.asTable({ maxColumnWidths }) : '')
)
},
}
}
......@@ -233,10 +232,11 @@ export function utsStracktraceyPreset(
opts: UtsStracktraceyPreset
): StacktraceyPreset {
let stack: Stacktracey
let errStack: string[] = []
return {
parseSourceMapUrl(file, fileName) {
// 根据 base,filename 组合 sourceMapUrl
return `${opts.base}/${fileName}.map`
return `${opts.base}${file.replace(opts.sourceRoot, '')}.map`
},
getSourceMapContent(file, fileName) {
// 根据 base,filename 组合 sourceMapUrl
......@@ -248,7 +248,7 @@ export function utsStracktraceyPreset(
const lines = (str || '').split('\n')
const entries = lines
.map((line) => {
.map((line, index) => {
line = line.trim()
let callee,
......@@ -256,17 +256,19 @@ export function utsStracktraceyPreset(
planA,
planB
if ((planA = line.match(/e: \[(.+)\](.+): (.+)/))) {
callee = planA[1]
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
errStack.push('%StacktraceyItem%')
callee = 'e: '
fileLineColumn = (
planA[2].match(/(.+):.*\((\d+).+?(\d+)\)/) || []
planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []
).slice(1)
} else {
errStack.push(line)
return undefined
}
const fileName = fileLineColumn[0]
? (planB = fileLineColumn[0].match(/(\/.*)*\/(.+)/) || [])[2] || ''
const fileName = planA[1]
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
: ''
return {
......@@ -274,9 +276,9 @@ export function utsStracktraceyPreset(
callee: callee || '',
index: false,
native: false,
file: nixSlashes(fileLineColumn[0] || ''),
line: parseInt(fileLineColumn[1] || '', 10) || undefined,
column: parseInt(fileLineColumn[2] || '', 10) || undefined,
file: nixSlashes(planA[1] || ''),
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
fileName,
fileShort: planB ? planB[1] : '',
errMsg: planA[3] || '',
......@@ -292,19 +294,16 @@ export function utsStracktraceyPreset(
})
},
asTableStacktrace({ stacktrace } = { stacktrace: '' }) {
const stacktraceSplit = stacktrace.split('\n')
const errorName = stacktraceSplit[0]
const errorMsg = stacktraceSplit.pop()
return (
(errorName.indexOf('e:') === -1 ? `${errorName}\n` : '') +
(stack.items
.map(
(item) =>
`e: [${item.callee}]${item.fileShort}/${item.fileName}: (${item.line}, ${item.column}): ${item.errMsg}`
)
.join('\n') +
(errorMsg ? `\n\n${errorMsg}` : ''))
)
return errStack
.map((item) => {
if (item === '%StacktraceyItem%') {
const _stack = stack.items.shift()
if (_stack)
return `${_stack.callee}${_stack.fileShort}/${_stack.fileName}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`
}
return item
})
.join('\n')
},
}
}
......@@ -5,34 +5,45 @@ const {
} = require('../dist/uni-stacktracey.cjs.js')
const utsErrorMsg = `Appid: __UNI__E070870
e: [PackagePath]/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (8, 1): Expecting a top level declaration
e: [PackagePath]/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (8, 9): Expecting a top level declaration
e: [PackagePath]/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (8, 10): Expecting a top level declaration
e: [PackagePath]/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (8, 11): Expecting a top level declaration
e: [PackagePath]/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (8, 16): Expecting a top level declaration
FAILURE: Build failed with an exception.`
stacktracey(
`ReferenceError: Sentry is not defined
at Proxy.throwError(/vue3/assets/pages-index-index.4077a069.js:1:295)
at e(/vue3/assets/index.2be9343a.js:1:52317)
at Ue(/vue3/assets/index.2be9343a.js:1:16271)
at He(/vue3/assets/index.2be9343a.js:1:16349)
at HTMLElement.n(/vue3/assets/index.2be9343a.js:1:51834)
at HTMLElement.o(/vue3/assets/index.2be9343a.js:21:60087)`,
{
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestComponent.kt: (68, 9): Unresolved reference: hello
e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (30, 9): Unresolved reference: hello
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s`
const uniErrorMsg = `ReferenceError: Sentry is not defined
at Proxy.throwError(/vue3/assets/pages-index-index.4077a069.js:1:295)
at e(/vue3/assets/index.2be9343a.js:1:52317)
at Ue(/vue3/assets/index.2be9343a.js:1:16271)
at He(/vue3/assets/index.2be9343a.js:1:16349)
at HTMLElement.n(/vue3/assets/index.2be9343a.js:1:51834)
at HTMLElement.o(/vue3/assets/index.2be9343a.js:21:60087)`
stacktracey(uniErrorMsg, {
preset: uniStracktraceyPreset({
base: 'https://7463-tcb-uzyfn59tqxjxtnbab2e2c-5ba40b-1303909289.tcb.qcloud.la',
platform: 'h5',
version: '1.0.0',
}),
}
).then((res) => console.log(res))
}).then((res) => {
console.log('res :>> ', res)
})
/* stacktracey(utsErrorMsg, {
preset: utsStracktraceyPreset({
base: '/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin',
sourceRoot: '',
base: '/usr/fxy/poroject/test/.sourcemap/src/',
sourceRoot:
'/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/',
}),
}).then((res) => console.log(res)) */
}).then((res) => {
console.log('res :>> ', res);
}) */
......@@ -15,6 +15,10 @@
"lib": [
"ESNext",
"DOM"
],
"types": [
"node",
"@dcloudio/types"
]
},
"include": [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册