@@ -109,7 +109,10 @@ func NewErrorBuilder() ErrorBuilder {
109
109
}
110
110
111
111
type stackTrace struct {
112
- frames []string
112
+ // frameCount is the number of stack frame currently pushed into lines.
113
+ frameCount int
114
+ // lines contains the stack trace and possibly the inlined source code information.
115
+ lines []string
113
116
}
114
117
115
118
// GoRuntimeErrorTracePrefix is the prefix coming before the Go runtime stack trace included in the face of runtime.Error.
@@ -125,7 +128,7 @@ func (s *stackTrace) FromRecovered(recovered interface{}) error {
125
128
return exitErr
126
129
}
127
130
128
- stack := strings .Join (s .frames , "\n \t " )
131
+ stack := strings .Join (s .lines , "\n \t " )
129
132
130
133
// If the error was internal, don't mention it was recovered.
131
134
if wasmErr , ok := recovered .(* wasmruntime.Error ); ok {
@@ -152,12 +155,16 @@ const MaxFrames = 30
152
155
153
156
// AddFrame implements ErrorBuilder.AddFrame
154
157
func (s * stackTrace ) AddFrame (funcName string , paramTypes , resultTypes []api.ValueType , sources []string ) {
158
+ if s .frameCount == MaxFrames {
159
+ return
160
+ }
161
+ s .frameCount ++
155
162
sig := signature (funcName , paramTypes , resultTypes )
156
- s .frames = append (s .frames , sig )
163
+ s .lines = append (s .lines , sig )
157
164
for _ , source := range sources {
158
- s .frames = append (s .frames , "\t " + source )
165
+ s .lines = append (s .lines , "\t " + source )
159
166
}
160
- if len ( s . frames ) == MaxFrames {
161
- s .frames = append (s .frames , "... maybe followed by omitted frames" )
167
+ if s . frameCount == MaxFrames {
168
+ s .lines = append (s .lines , "... maybe followed by omitted frames" )
162
169
}
163
170
}
0 commit comments