@@ -200,8 +200,22 @@ func (iter *Iterator) ReportError(operation string, msg string) {
200
200
if peekStart < 0 {
201
201
peekStart = 0
202
202
}
203
- iter .Error = fmt .Errorf ("%s: %s, parsing %v ...%s... at %s" , operation , msg , iter .head ,
204
- string (iter .buf [peekStart :iter .head ]), string (iter .buf [0 :iter .tail ]))
203
+ peekEnd := iter .head + 10
204
+ if peekEnd > iter .tail {
205
+ peekEnd = iter .tail
206
+ }
207
+ parsing := string (iter .buf [peekStart :peekEnd ])
208
+ contextStart := iter .head - 50
209
+ if contextStart < 0 {
210
+ contextStart = 0
211
+ }
212
+ contextEnd := iter .head + 50
213
+ if contextEnd > iter .tail {
214
+ contextEnd = iter .tail
215
+ }
216
+ context := string (iter .buf [contextStart :contextEnd ])
217
+ iter .Error = fmt .Errorf ("%s: %s, error found in #%v byte of ...|%s|..., bigger context ...|%s|..." ,
218
+ operation , msg , iter .head - peekStart , parsing , context )
205
219
}
206
220
207
221
// CurrentBuffer gets current buffer as string for debugging purpose
@@ -210,7 +224,7 @@ func (iter *Iterator) CurrentBuffer() string {
210
224
if peekStart < 0 {
211
225
peekStart = 0
212
226
}
213
- return fmt .Sprintf ("parsing %v ...|%s|... at %s " , iter .head ,
227
+ return fmt .Sprintf ("parsing # %v byte, around ...|%s|..., whole buffer ...|%s|... " , iter .head ,
214
228
string (iter .buf [peekStart :iter .head ]), string (iter .buf [0 :iter .tail ]))
215
229
}
216
230
0 commit comments