awaitLet report async errors in kiss-VSCode commands

This commit is contained in:
2021-10-16 23:39:00 -04:00
parent 9bc535b489
commit 8f88149282
2 changed files with 12 additions and 7 deletions

View File

@@ -626,14 +626,16 @@ class Macros {
]); ]);
}; };
// TODO test this
function awaitLet(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) { function awaitLet(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) {
wholeExp.checkNumArgs(2, null, "(awaitLet [[promise bindings...]] [body...])"); wholeExp.checkNumArgs(2, null, "(awaitLet [<promise bindings...>] <body...>)");
var bindingList = exps[0].bindingList("awaitLet"); var bindingList = exps[0].bindingList("awaitLet");
var firstName = bindingList.shift(); var firstName = bindingList.shift();
var firstValue = bindingList.shift(); var firstValue = bindingList.shift();
var b = wholeExp.expBuilder(); var b = wholeExp.expBuilder();
var firstNameStr = firstName.symbolNameValue();
var error = b.callSymbol("+", [b.str('awaitLet $firstNameStr rejected promise: '), b.symbol("reason")]);
return b.call(b.field("then", firstValue), [ return b.call(b.field("then", firstValue), [
b.call(b.symbol("lambda"), [ b.call(b.symbol("lambda"), [
b.list([firstName]), b.list([firstName]),
@@ -646,10 +648,13 @@ class Macros {
// Handle rejections: // Handle rejections:
b.call(b.symbol("lambda"), [ b.call(b.symbol("lambda"), [
b.list([b.symbol("reason")]), b.list([b.symbol("reason")]),
b.call(b.symbol("throw"), [ b.callSymbol("#when", [
// TODO generalize CompileError to KissError which will also handle runtime errors b.symbol("vscode"),
// with the same source position format b.callSymbol("errorMessage", [error]),
b.str("rejected promise") ]),
// If running VSCode js, this throw will be a no-op but it makes the expression type-unify:
b.callSymbol("throw", [
error
]) ])
]) ])
]); ]);

View File

@@ -286,7 +286,7 @@ class SpecialForms {
// Type check syntax: // Type check syntax:
map["the"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> { map["the"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(2, 3, '(the [optional: package] [type] [value])'); wholeExp.checkNumArgs(2, 3, '(the <?package> <type> <value>)');
var pkg = ""; var pkg = "";
var whichArg = "first"; var whichArg = "first";
if (args.length == 3) { if (args.length == 3) {