Skip to content

Commit 3ab82aa

Browse files
committed
feat: introduce ErrTooManySteps
1 parent 8230c71 commit 3ab82aa

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

starlark/eval_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,9 @@ func TestExecutionSteps(t *testing.T) {
11581158
if !errors.As(err, &canceledErr) {
11591159
t.Errorf("execution didn't return error starlark.CanceledError")
11601160
}
1161+
if !errors.Is(err, starlark.ErrTooManySteps) {
1162+
t.Errorf("execution didn't return error starlark.ErrTooManySteps")
1163+
}
11611164

11621165
thread.Steps = 0
11631166
thread.Uncancel()

starlark/interp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"fmt"
77
"os"
88

9+
"errors"
910
"go.starlark.net/internal/compile"
1011
"go.starlark.net/internal/spell"
1112
"go.starlark.net/syntax"
1213
)
1314

1415
const vmdebug = false // TODO(adonovan): use a bitfield of specific kinds of error.
1516

17+
var ErrTooManySteps = errors.New("too many steps")
18+
1619
// TODO(adonovan):
1720
// - optimize position table.
1821
// - opt: record MaxIterStack during compilation and preallocate the stack.
@@ -100,7 +103,7 @@ loop:
100103
if thread.OnMaxSteps != nil {
101104
thread.OnMaxSteps(thread)
102105
} else {
103-
thread.Cancel("too many steps")
106+
thread.CancelWithError(ErrTooManySteps)
104107
}
105108
}
106109
if reasonErr := thread.cancelReason.Load(); reasonErr != nil {

0 commit comments

Comments
 (0)