Skip to content

Commit

Permalink
get_error if we need it later
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Nov 14, 2024
1 parent 832de18 commit 66e274e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
10 changes: 5 additions & 5 deletions trealla/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions trealla/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions trealla/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 66e274e

Please sign in to comment.