Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
b6a4ec7d
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b6a4ec7d
编写于
8月 27, 2019
作者:
N
Nayeem Rahman
提交者:
Ryan Dahl
8月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve error stacks for async ops (#2820)
上级
725eb981
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
57 addition
and
39 deletion
+57
-39
js/dispatch_json.ts
js/dispatch_json.ts
+29
-33
js/dispatch_json_test.ts
js/dispatch_json_test.ts
+19
-0
js/test_util.ts
js/test_util.ts
+3
-1
js/unit_tests.ts
js/unit_tests.ts
+1
-0
tests/error_004_missing_module.ts.out
tests/error_004_missing_module.ts.out
+1
-1
tests/error_005_missing_dynamic_import.ts.out
tests/error_005_missing_dynamic_import.ts.out
+1
-1
tests/error_006_import_ext_failure.ts.out
tests/error_006_import_ext_failure.ts.out
+1
-1
tests/error_011_bad_module_specifier.ts.out
tests/error_011_bad_module_specifier.ts.out
+1
-1
tests/error_012_bad_dynamic_import_specifier.ts.out
tests/error_012_bad_dynamic_import_specifier.ts.out
+1
-1
未找到文件。
js/dispatch_json.ts
浏览文件 @
b6a4ec7d
...
...
@@ -15,10 +15,10 @@ interface JsonError {
interface
JsonResponse
{
ok
?:
Ok
;
err
?:
JsonError
;
promiseId
?:
number
;
//
only present in async mesas
ges.
promiseId
?:
number
;
//
Only present in async messa
ges.
}
const
promiseTable
=
new
Map
<
number
,
util
.
Resolvable
<
number
>>
();
const
promiseTable
=
new
Map
<
number
,
util
.
Resolvable
<
JsonResponse
>>
();
let
_nextPromiseId
=
1
;
function
nextPromiseId
():
number
{
...
...
@@ -35,25 +35,22 @@ function encode(args: object): Uint8Array {
return
new
TextEncoder
().
encode
(
s
);
}
function
toDenoError
(
err
:
JsonError
):
DenoError
<
ErrorKind
>
{
return
new
DenoError
(
err
.
kind
,
err
.
message
);
function
unwrapResponse
(
res
:
JsonResponse
):
Ok
{
if
(
res
.
err
!=
null
)
{
throw
new
DenoError
(
res
.
err
!
.
kind
,
res
.
err
!
.
message
);
}
util
.
assert
(
res
.
ok
!=
null
);
return
res
.
ok
!
;
}
export
function
asyncMsgFromRust
(
opId
:
number
,
res
:
Uint8Array
):
void
{
const
{
ok
,
err
,
promiseId
}
=
decode
(
res
);
const
promise
=
promiseTable
.
get
(
promiseId
!
)
!
;
if
(
!
promise
)
{
throw
Error
(
`Async op
${
opId
}
had bad promiseId`
);
}
promiseTable
.
delete
(
promiseId
!
);
export
function
asyncMsgFromRust
(
opId
:
number
,
resUi8
:
Uint8Array
):
void
{
const
res
=
decode
(
resUi8
);
util
.
assert
(
res
.
promiseId
!=
null
);
if
(
err
)
{
promise
.
reject
(
toDenoError
(
err
));
}
else
if
(
ok
)
{
promise
.
resolve
(
ok
);
}
else
{
util
.
unreachable
();
}
const
promise
=
promiseTable
.
get
(
res
.
promiseId
!
);
util
.
assert
(
promise
!=
null
);
promiseTable
.
delete
(
res
.
promiseId
!
);
promise
!
.
resolve
(
res
);
}
export
function
sendSync
(
...
...
@@ -62,29 +59,28 @@ export function sendSync(
zeroCopy
?:
Uint8Array
):
Ok
{
const
argsUi8
=
encode
(
args
);
const
res
=
core
.
dispatch
(
opId
,
argsUi8
,
zeroCopy
);
if
(
!
res
)
{
return
;
}
const
{
ok
,
err
,
promiseId
}
=
decode
(
res
);
util
.
assert
(
!
promiseId
);
if
(
err
)
{
throw
toDenoError
(
err
);
}
return
ok
;
const
resUi8
=
core
.
dispatch
(
opId
,
argsUi8
,
zeroCopy
);
util
.
assert
(
resUi8
!=
null
);
const
res
=
decode
(
resUi8
!
);
util
.
assert
(
res
.
promiseId
==
null
);
return
unwrapResponse
(
res
);
}
export
function
sendAsync
(
export
async
function
sendAsync
(
opId
:
number
,
args
:
object
=
{},
zeroCopy
?:
Uint8Array
):
Promise
<
Ok
>
{
const
promiseId
=
nextPromiseId
();
args
=
Object
.
assign
(
args
,
{
promiseId
});
const
argsUi8
=
encode
(
args
);
const
promise
=
util
.
createResolvable
<
Ok
>
();
promiseTable
.
set
(
promiseId
,
promise
);
const
r
=
core
.
dispatch
(
opId
,
argsUi8
,
zeroCopy
);
util
.
assert
(
!
r
);
return
promise
;
const
argsUi8
=
encode
(
args
);
const
resUi8
=
core
.
dispatch
(
opId
,
argsUi8
,
zeroCopy
);
util
.
assert
(
resUi8
==
null
);
const
res
=
await
promise
;
return
unwrapResponse
(
res
);
}
js/dispatch_json_test.ts
0 → 100644
浏览文件 @
b6a4ec7d
import
{
testPerm
,
assertMatch
,
unreachable
}
from
"
./test_util.ts
"
;
const
openErrorStackPattern
=
new
RegExp
(
`^.*
at unwrapResponse \\(js\\/dispatch_json\\.ts:.*\\)
at sendAsync.* \\(js\\/dispatch_json\\.ts:.*\\)
at async Object\\.open \\(js\\/files\\.ts:.*\\).*$`
,
"
ms
"
);
testPerm
({
read
:
true
},
async
function
sendAsyncStackTrace
():
Promise
<
void
>
{
await
Deno
.
open
(
"
nonexistent.txt
"
)
.
then
(
unreachable
)
.
catch
(
(
error
):
void
=>
{
assertMatch
(
error
.
stack
,
openErrorStackPattern
);
}
);
});
js/test_util.ts
浏览文件 @
b6a4ec7d
...
...
@@ -15,9 +15,11 @@ import {
export
{
assert
,
assertEquals
,
assertMatch
,
assertNotEquals
,
assertStrictEq
,
assertStrContains
assertStrContains
,
unreachable
}
from
"
./deps/https/deno.land/std/testing/asserts.ts
"
;
interface
TestPermissions
{
...
...
js/unit_tests.ts
浏览文件 @
b6a4ec7d
...
...
@@ -13,6 +13,7 @@ import "./console_test.ts";
import
"
./copy_file_test.ts
"
;
import
"
./custom_event_test.ts
"
;
import
"
./dir_test.ts
"
;
import
"
./dispatch_json_test.ts
"
;
import
"
./error_stack_test.ts
"
;
import
"
./event_test.ts
"
;
import
"
./event_target_test.ts
"
;
...
...
tests/error_004_missing_module.ts.out
浏览文件 @
b6a4ec7d
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts"
[WILDCARD] js/dispatch_json.ts:[WILDCARD]
at DenoError (js/errors.ts:[WILDCARD])
at
toDenoError
(js/dispatch_json.ts:[WILDCARD])
at
unwrapResponse
(js/dispatch_json.ts:[WILDCARD])
at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
at fetchSourceFile (js/compiler.ts:[WILDCARD])
at _resolveModule (js/compiler.ts:[WILDCARD])
...
...
tests/error_005_missing_dynamic_import.ts.out
浏览文件 @
b6a4ec7d
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts"
[WILDCARD] js/dispatch_json.ts:[WILDCARD]
at DenoError (js/errors.ts:[WILDCARD])
at
toDenoError
(js/dispatch_json.ts:[WILDCARD])
at
unwrapResponse
(js/dispatch_json.ts:[WILDCARD])
at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
at fetchSourceFile (js/compiler.ts:[WILDCARD])
at _resolveModule (js/compiler.ts:[WILDCARD])
...
...
tests/error_006_import_ext_failure.ts.out
浏览文件 @
b6a4ec7d
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/non-existent"
[WILDCARD] js/dispatch_json.ts:[WILDCARD]
at DenoError (js/errors.ts:[WILDCARD])
at
toDenoError
(js/dispatch_json.ts:[WILDCARD])
at
unwrapResponse
(js/dispatch_json.ts:[WILDCARD])
at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
at fetchSourceFile (js/compiler.ts:[WILDCARD])
at _resolveModule (js/compiler.ts:[WILDCARD])
...
...
tests/error_011_bad_module_specifier.ts.out
浏览文件 @
b6a4ec7d
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../
[WILDCARD] js/dispatch_json.ts:[WILDCARD]
at DenoError (js/errors.ts:[WILDCARD])
at
toDenoError
(js/dispatch_json.ts:[WILDCARD])
at
unwrapResponse
(js/dispatch_json.ts:[WILDCARD])
at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
at fetchSourceFile (js/compiler.ts:[WILDCARD])
at _resolveModule (js/compiler.ts:[WILDCARD])
...
...
tests/error_012_bad_dynamic_import_specifier.ts.out
浏览文件 @
b6a4ec7d
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../
[WILDCARD] js/dispatch_json.ts:[WILDCARD]
at DenoError (js/errors.ts:[WILDCARD])
at
toDenoError
(js/dispatch_json.ts:[WILDCARD])
at
unwrapResponse
(js/dispatch_json.ts:[WILDCARD])
at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
at fetchSourceFile (js/compiler.ts:[WILDCARD])
at _resolveModule (js/compiler.ts:[WILDCARD])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录