Skip to content

Commit aea70b0

Browse files
committed
feat: introduce ErrTooManySteps
1 parent d6cb780 commit aea70b0

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
@@ -1213,6 +1213,9 @@ func TestExecutionSteps(t *testing.T) {
12131213
if !errors.As(err, &canceledErr) {
12141214
t.Errorf("execution didn't return error starlark.CanceledError")
12151215
}
1216+
if !errors.Is(err, starlark.ErrTooManySteps) {
1217+
t.Errorf("execution didn't return error starlark.ErrTooManySteps")
1218+
}
12161219

12171220
thread.Steps = 0
12181221
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.
@@ -110,7 +113,7 @@ loop:
110113
if thread.OnMaxSteps != nil {
111114
thread.OnMaxSteps(thread)
112115
} else {
113-
thread.Cancel("too many steps")
116+
thread.CancelWithError(ErrTooManySteps)
114117
}
115118
}
116119
if reasonErr := thread.cancelReason.Load(); reasonErr != nil {

0 commit comments

Comments
 (0)