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