From 66e274e971349e1b3adb2b961e58c6f08c144c5a Mon Sep 17 00:00:00 2001 From: guregu Date: Thu, 14 Nov 2024 23:04:35 +0900 Subject: [PATCH] get_error if we need it later --- trealla/prolog.go | 10 +++++----- trealla/query.go | 30 ++++++++++++++++++++++++++++++ trealla/query_test.go | 18 ++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/trealla/prolog.go b/trealla/prolog.go index 8fce3ed..70f031e 100644 --- a/trealla/prolog.go +++ b/trealla/prolog.go @@ -65,7 +65,7 @@ type prolog struct { pl_query wasmFunc pl_redo wasmFunc pl_done wasmFunc - pl_error wasmFunc + // get_error wasmFunc procs map[string]Predicate coros map[int64]coroutine @@ -194,10 +194,10 @@ func (pl *prolog) init(parent *prolog) error { return err } - pl.pl_error, err = pl.function("pl_error") - if err != nil { - return err - } + // pl.get_error, err = pl.function("get_error") + // if err != nil { + // return err + // } pl.pl_consult, err = pl.function("pl_consult") if err != nil { diff --git a/trealla/query.go b/trealla/query.go index c24b0be..ecea5ec 100644 --- a/trealla/query.go +++ b/trealla/query.go @@ -321,6 +321,18 @@ func (q *query) redo(ctx context.Context) bool { return false } + // var erroring bool + // var errcode uint64 + // { + // retv, err2 := pl.get_error.Call(ctx, uint64(pl.ptr)) + // if err2 != nil { + // q.setError(fmt.Errorf("trealla: get_error internal error: %w", err)) + // return false + // } + // errcode = retv[0] + // erroring = errcode != 0 + // } + if q.done { delete(pl.running, q.subquery) // defer q.close() @@ -339,6 +351,24 @@ func (q *query) redo(ctx context.Context) bool { stderr := q.stderr.String() q.resetOutput() + // if erroring { + // var msg string + // if either := cmp.Or(stdout, stderr); either != "" { + // either = strings.TrimPrefix(either, "\x02") + // if strings.HasPrefix(either, "Error:") || strings.HasPrefix(either, "Warning:") { + // nl := strings.IndexByte(either, '\n') + // if nl > 0 { + // msg = either[:nl] + // } + // } + // } + // if msg == "" { + // msg = fmt.Sprintf("interpreter returned error code %d", errcode) + // } + // q.setError(fmt.Errorf("%s", msg)) + // return false + // } + ans, err := pl.parse(q.goal, stdout, stderr) switch { case IsFailure(err): diff --git a/trealla/query_test.go b/trealla/query_test.go index 2d4f624..3dd8d6a 100644 --- a/trealla/query_test.go +++ b/trealla/query_test.go @@ -311,6 +311,24 @@ func TestThrow(t *testing.T) { } } +// func TestInterpError(t *testing.T) { +// pl, err := trealla.New() +// if err != nil { +// t.Fatal(err) +// } + +// ctx := context.Background() +// q := pl.Query(ctx, `abort.`) +// if q.Next(ctx) { +// t.Error("unexpected result", q.Current()) +// } +// err = q.Err() +// t.Fatal(err) +// if err == nil { +// t.Fatal("expected error") +// } +// } + func TestPreopen(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping unixy test")