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) {
wholeExp.checkNumArgs(2, null, "(awaitLet [[promise bindings...]] [body...])");
wholeExp.checkNumArgs(2, null, "(awaitLet [<promise bindings...>] <body...>)");
var bindingList = exps[0].bindingList("awaitLet");
var firstName = bindingList.shift();
var firstValue = bindingList.shift();
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), [
b.call(b.symbol("lambda"), [
b.list([firstName]),
@@ -646,10 +648,13 @@ class Macros {
// Handle rejections:
b.call(b.symbol("lambda"), [
b.list([b.symbol("reason")]),
b.call(b.symbol("throw"), [
// TODO generalize CompileError to KissError which will also handle runtime errors
// with the same source position format
b.str("rejected promise")
b.callSymbol("#when", [
b.symbol("vscode"),
b.callSymbol("errorMessage", [error]),
]),
// 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:
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 whichArg = "first";
if (args.length == 3) {