File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ()
Original file line number Diff line number Diff 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
1415const 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 {
You can’t perform that action at this time.
0 commit comments