Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
4da4b289
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4da4b289
编写于
5月 19, 2022
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: uni-stacktracey readme
上级
4ab19605
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
139 addition
and
29 deletion
+139
-29
packages/uni-stacktracey/README.md
packages/uni-stacktracey/README.md
+113
-0
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
+6
-7
packages/uni-stacktracey/dist/uni-stacktracey.es.js
packages/uni-stacktracey/dist/uni-stacktracey.es.js
+6
-7
packages/uni-stacktracey/src/index.ts
packages/uni-stacktracey/src/index.ts
+14
-15
未找到文件。
packages/uni-stacktracey/README.md
0 → 100644
浏览文件 @
4da4b289
### uni-stacktracey 使用说明
#### 引用方式
```
js
const
{
sourcemap
:
{
stacktracey
,
uniStracktraceyPreset
,
utsStracktraceyPreset
},
}
=
require
(
'
${HBuilderX}/plugins/uniapp-cli-vite
'
)
```
#### stacktracey 方法
**stacktracey 方法有两个参数:**
1.
stacktrace
2.
opts
##### stacktrace 参数说明
> 一个错误堆栈。String 类型
**示例**
```
js
// js 错误堆栈
const
uniErrorMsg
=
`Error: Sentry Error
at a.throwError(/static/js/pages-index-index.3ab0d0e5.js:1:567)
at click(/static/js/pages-index-index.3ab0d0e5.js:1:2745)
at ee(/static/js/chunk-vendors.75525bd5.js:34:11927)
at n(/static/js/chunk-vendors.75525bd5.js:34:13747)
at ee(/static/js/chunk-vendors.75525bd5.js:34:11927)
at HTMLElement.n(/static/js/chunk-vendors.75525bd5.js:34:13824)
at HTMLElement.o._wrapper(/static/js/chunk-vendors.75525bd5.js:34:53966)
at HTMLElement.i(/static/js/chunk-vendors.75525bd5.js:7:609894)`
// uts 错误堆栈
const
utsErrorMsg
=
`e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (9, 5): Unresolved reference: logxxxxxxx
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 2s
`
```
#### opts 参数说明
> 解析生成错误栈时需要用到的一些方法。
> 此处提供了生成该参数的两种预设方案:uniStracktraceyPreset、utsStracktraceyPreset
**预设一:`uniStracktraceyPreset`**
> 解析 js 错误栈的预设方案
```
js
// 调用方式
stacktracey
(
uniErrorMsg
,
{
preset
:
uniStracktraceyPreset
({
base
:
path
.
resolve
(
__dirname
,
'
./__UNI__APPID__/1.0.0/.sourcemap/h5/
'
),
sourceRoot
:
''
,
}),
}).
then
((
stacktrace
)
=>
{
// stacktrace 即为解析 sourcemap 后的错误信息
console
.
log
(
'
stacktrace :>>
'
,
stacktrace
)
})
```
**预设二:`utsStracktraceyPreset`**
> 解析 uts 错误栈的预设方案
```
js
// 调用方式
stacktracey
(
utsErrorMsg
,
{
preset
:
utsStracktraceyPreset
({
base
:
path
.
resolve
(
__dirname
,
'
./nativeplugins-sourceMap/DCloud-UTSPlugin/
'
),
sourceRoot
:
'
DCloud-UTSPlugin/android/src/
'
,
}),
}).
then
((
stacktrace
)
=>
{
// stacktrace 即为解析 sourcemap 后的错误信息
console
.
log
(
'
stacktrace :>>
'
,
stacktrace
)
})
```
**预设方案的参数说明**
1.
`base`
:当前项目
`sourcemap`
文件路径。如果由
`http:、https:`
开头,则会发送网络请求获取
2.
`sourceRoot`
:当前项目资源路径
3.
详细说明
> 由上述 stacktrace 参数说明中 `utsErrorMsg` 为例
>
> 错误信息为 e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (9, 5): Unresolved reference: logxxxxxxx
-
第一步:根据
`sourceRoot`
解析出包含 path 的 fileName
-
比如,
`sourceRoot`
参数为:
`DCloud-UTSPlugin/android/src/`
-
解析出的
`fileName`
为:
`io/dcloud/uniplugin/TestModule.kt`
-
第二步:根据
`base + fileName`
参数拼接出
`sourcemap`
路径
-
比如,
`base`
参数为:
`C:/project/test-uni/.sourcemap/`
-
解析出的
`sourcemap`
路径为
`C:/project/test-uni/.sourcemap/io/dcloud/uniplugin/TestModule.kt.map`
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
浏览文件 @
4da4b289
...
@@ -53,6 +53,7 @@ function stacktracey(stacktrace, opts) {
...
@@ -53,6 +53,7 @@ function stacktracey(stacktrace, opts) {
Promise
.
all
(
parseStack
)
Promise
.
all
(
parseStack
)
.
then
(()
=>
{
.
then
(()
=>
{
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
stack
,
maxColumnWidths
:
{
maxColumnWidths
:
{
callee
:
999
,
callee
:
999
,
file
:
999
,
file
:
999
,
...
@@ -113,7 +114,6 @@ function parseSourceMapContent(consumer, obj) {
...
@@ -113,7 +114,6 @@ function parseSourceMapContent(consumer, obj) {
}
}
function
uniStracktraceyPreset
(
opts
)
{
function
uniStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
return
{
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
parseSourceMapUrl
(
file
,
fileName
)
{
// 组合 sourceMapUrl
// 组合 sourceMapUrl
...
@@ -131,9 +131,9 @@ function uniStracktraceyPreset(opts) {
...
@@ -131,9 +131,9 @@ function uniStracktraceyPreset(opts) {
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
},
},
parseStacktrace
(
stacktrace
)
{
parseStacktrace
(
stacktrace
)
{
return
(
stack
=
new
StackTracey__default
[
"
default
"
](
stacktrace
)
);
return
new
StackTracey__default
[
"
default
"
](
stacktrace
);
},
},
asTableStacktrace
({
maxColumnWidths
,
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
];
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
];
return
((
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
return
((
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
(
stack
.
asTable
?
stack
.
asTable
({
maxColumnWidths
})
:
''
));
(
stack
.
asTable
?
stack
.
asTable
({
maxColumnWidths
})
:
''
));
...
@@ -142,7 +142,6 @@ function uniStracktraceyPreset(opts) {
...
@@ -142,7 +142,6 @@ function uniStracktraceyPreset(opts) {
}
}
function
utsStracktraceyPreset
(
opts
)
{
function
utsStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
let
errStack
=
[];
let
errStack
=
[];
return
{
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
parseSourceMapUrl
(
file
,
fileName
)
{
...
@@ -191,11 +190,11 @@ function utsStracktraceyPreset(opts) {
...
@@ -191,11 +190,11 @@ function utsStracktraceyPreset(opts) {
};
};
})
})
.
filter
((
x
)
=>
x
!==
undefined
);
.
filter
((
x
)
=>
x
!==
undefined
);
return
(
stack
=
{
return
{
items
:
entries
,
items
:
entries
,
}
)
;
};
},
},
asTableStacktrace
({
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
return
errStack
return
errStack
.
map
((
item
)
=>
{
.
map
((
item
)
=>
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
...
...
packages/uni-stacktracey/dist/uni-stacktracey.es.js
浏览文件 @
4da4b289
...
@@ -51,6 +51,7 @@ function stacktracey(stacktrace, opts) {
...
@@ -51,6 +51,7 @@ function stacktracey(stacktrace, opts) {
Promise
.
all
(
parseStack
)
Promise
.
all
(
parseStack
)
.
then
(()
=>
{
.
then
(()
=>
{
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
stack
,
maxColumnWidths
:
{
maxColumnWidths
:
{
callee
:
999
,
callee
:
999
,
file
:
999
,
file
:
999
,
...
@@ -111,7 +112,6 @@ function parseSourceMapContent(consumer, obj) {
...
@@ -111,7 +112,6 @@ function parseSourceMapContent(consumer, obj) {
}
}
function
uniStracktraceyPreset
(
opts
)
{
function
uniStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
return
{
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
parseSourceMapUrl
(
file
,
fileName
)
{
// 组合 sourceMapUrl
// 组合 sourceMapUrl
...
@@ -129,9 +129,9 @@ function uniStracktraceyPreset(opts) {
...
@@ -129,9 +129,9 @@ function uniStracktraceyPreset(opts) {
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
},
},
parseStacktrace
(
stacktrace
)
{
parseStacktrace
(
stacktrace
)
{
return
(
stack
=
new
StackTracey
(
stacktrace
)
);
return
new
StackTracey
(
stacktrace
);
},
},
asTableStacktrace
({
maxColumnWidths
,
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
];
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
];
return
((
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
return
((
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
(
stack
.
asTable
?
stack
.
asTable
({
maxColumnWidths
})
:
''
));
(
stack
.
asTable
?
stack
.
asTable
({
maxColumnWidths
})
:
''
));
...
@@ -140,7 +140,6 @@ function uniStracktraceyPreset(opts) {
...
@@ -140,7 +140,6 @@ function uniStracktraceyPreset(opts) {
}
}
function
utsStracktraceyPreset
(
opts
)
{
function
utsStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
let
errStack
=
[];
let
errStack
=
[];
return
{
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
parseSourceMapUrl
(
file
,
fileName
)
{
...
@@ -189,11 +188,11 @@ function utsStracktraceyPreset(opts) {
...
@@ -189,11 +188,11 @@ function utsStracktraceyPreset(opts) {
};
};
})
})
.
filter
((
x
)
=>
x
!==
undefined
);
.
filter
((
x
)
=>
x
!==
undefined
);
return
(
stack
=
{
return
{
items
:
entries
,
items
:
entries
,
}
)
;
};
},
},
asTableStacktrace
({
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
return
errStack
return
errStack
.
map
((
item
)
=>
{
.
map
((
item
)
=>
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
...
...
packages/uni-stacktracey/src/index.ts
浏览文件 @
4da4b289
...
@@ -28,22 +28,23 @@ type Stacktracey = {
...
@@ -28,22 +28,23 @@ type Stacktracey = {
interface
StacktraceyPreset
{
interface
StacktraceyPreset
{
/**
/**
* 解析错误栈信息
* 解析错误栈信息
* @param
filenam
e
* @param
stacktrac
e
*/
*/
parseStacktrace
(
stacktrace
:
string
):
Stacktracey
parseStacktrace
(
stacktrace
:
string
):
Stacktracey
/**
/**
* 根据
错误信息重新赋值
为错误栈信息
* 根据
解析后的错误信息重新整合
为错误栈信息
* @param
filename
* @param
opts
*/
*/
asTableStacktrace
(
opts
?:
{
asTableStacktrace
(
opts
:
{
stack
:
Stacktracey
maxColumnWidths
?:
StackTracey
.
MaxColumnWidths
maxColumnWidths
?:
StackTracey
.
MaxColumnWidths
stacktrace
:
string
stacktrace
:
string
}):
string
}):
string
/**
/**
*
根据
编译后的文件名地址
* 编译后的文件名地址
* @param file
* @param file
*
根据
编译后的文件名
* 编译后的文件名
* @param file
n
ame
* @param file
N
ame
*/
*/
parseSourceMapUrl
(
file
:
string
,
fileName
:
string
):
string
parseSourceMapUrl
(
file
:
string
,
fileName
:
string
):
string
getSourceMapContent
(
file
:
string
,
fileName
:
string
):
Promise
<
string
>
getSourceMapContent
(
file
:
string
,
fileName
:
string
):
Promise
<
string
>
...
@@ -106,6 +107,7 @@ export function stacktracey(
...
@@ -106,6 +107,7 @@ export function stacktracey(
Promise
.
all
(
parseStack
)
Promise
.
all
(
parseStack
)
.
then
(()
=>
{
.
then
(()
=>
{
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
stack
,
maxColumnWidths
:
{
maxColumnWidths
:
{
callee
:
999
,
callee
:
999
,
file
:
999
,
file
:
999
,
...
@@ -195,8 +197,6 @@ export function uniStracktraceyPreset(
...
@@ -195,8 +197,6 @@ export function uniStracktraceyPreset(
):
StacktraceyPreset
{
):
StacktraceyPreset
{
const
{
base
,
sourceRoot
}
=
opts
const
{
base
,
sourceRoot
}
=
opts
let
stack
:
Stacktracey
return
{
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
parseSourceMapUrl
(
file
,
fileName
)
{
// 组合 sourceMapUrl
// 组合 sourceMapUrl
...
@@ -214,9 +214,9 @@ export function uniStracktraceyPreset(
...
@@ -214,9 +214,9 @@ export function uniStracktraceyPreset(
)
)
},
},
parseStacktrace
(
stacktrace
)
{
parseStacktrace
(
stacktrace
)
{
return
(
stack
=
new
StackTracey
(
stacktrace
)
)
return
new
StackTracey
(
stacktrace
)
},
},
asTableStacktrace
({
maxColumnWidths
,
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
]
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
]
return
(
return
(
(
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
(
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
...
@@ -241,7 +241,6 @@ export function utsStracktraceyPreset(
...
@@ -241,7 +241,6 @@ export function utsStracktraceyPreset(
):
StacktraceyPreset
{
):
StacktraceyPreset
{
const
{
base
,
sourceRoot
}
=
opts
const
{
base
,
sourceRoot
}
=
opts
let
stack
:
Stacktracey
let
errStack
:
string
[]
=
[]
let
errStack
:
string
[]
=
[]
return
{
return
{
...
@@ -303,11 +302,11 @@ export function utsStracktraceyPreset(
...
@@ -303,11 +302,11 @@ export function utsStracktraceyPreset(
})
})
.
filter
((
x
)
=>
x
!==
undefined
)
.
filter
((
x
)
=>
x
!==
undefined
)
return
(
stack
=
{
return
{
items
:
entries
as
StackTracey
.
Entry
[],
items
:
entries
as
StackTracey
.
Entry
[],
}
)
}
},
},
asTableStacktrace
({
stacktrace
}
=
{
stacktrace
:
''
})
{
asTableStacktrace
({
maxColumnWidths
,
stacktrace
,
stack
})
{
return
errStack
return
errStack
.
map
((
item
)
=>
{
.
map
((
item
)
=>
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录