Skip to content

Commit b8cb24c

Browse files
micvbangmarkus-wa
authored andcommitted
parsing: handle EOF and queue syncing
1 parent debf08a commit b8cb24c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

parsing.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ func (p *Parser) ParseHeader() (common.DemoHeader, error) {
7070
// See also: ParseNextFrame() for other possible errors.
7171
func (p *Parser) ParseToEnd() (err error) {
7272
defer func() {
73+
// Make sure all the messages of the demo are handled
74+
p.msgDispatcher.SyncAllQueues()
75+
76+
// Close msgQueue
77+
if p.msgQueue != nil {
78+
close(p.msgQueue)
79+
}
80+
7381
if err == nil {
7482
err = recoverFromUnexpectedEOF(recover())
7583
}
@@ -89,12 +97,6 @@ func (p *Parser) ParseToEnd() (err error) {
8997

9098
default:
9199
if !p.parseFrame() {
92-
// Make sure all the messages of the demo are handled
93-
p.msgDispatcher.SyncAllQueues()
94-
95-
// Close msgQueue
96-
close(p.msgQueue)
97-
98100
return p.error()
99101
}
100102
}
@@ -107,7 +109,7 @@ func (p *Parser) ParseToEnd() (err error) {
107109

108110
func recoverFromUnexpectedEOF(r interface{}) error {
109111
if r != nil {
110-
if r == io.ErrUnexpectedEOF {
112+
if r == io.ErrUnexpectedEOF || r == io.EOF {
111113
return ErrUnexpectedEndOfDemo
112114
}
113115
panic(r)

0 commit comments

Comments
 (0)