Skip to content

Commit

Permalink
Handle ErrUnexpectedEndOfDemo gracefully. (pnxenopoulos#276)
Browse files Browse the repository at this point in the history
* Handle ErrUnexpectedEndOfDemo gracefully.

* Fixed golang linter warning
  • Loading branch information
JanEricNitschke authored Jul 29, 2023
1 parent 5a16293 commit 688d4ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ dmypy.json
.pytype/

# csgo demofiles
.dem
*.dem

# vscode
*code-workspace
Expand Down
29 changes: 17 additions & 12 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"math"
"os"
"strconv"
Expand Down Expand Up @@ -2514,18 +2516,11 @@ func registerFrameHandler(demoParser *dem.Parser, currentGame *Game, currentRoun
appendFrameToRound(currentRound, &currentFrame, globalFrameIndex)
}
}

if *currentFrameIdx == (currentGame.ParsingOpts.ParseRate - 1) {
*currentFrameIdx = 0
} else {
*currentFrameIdx++
}
}
if *currentFrameIdx == (currentGame.ParsingOpts.ParseRate - 1) {
*currentFrameIdx = 0
} else {
if *currentFrameIdx == (currentGame.ParsingOpts.ParseRate - 1) {
*currentFrameIdx = 0
} else {
*currentFrameIdx++
}
*currentFrameIdx++
}
})
}
Expand Down Expand Up @@ -2580,6 +2575,9 @@ func main() {
The parserate should be one of 2^0 to 2^7. The lower the value, the more frames are collected.
Indicates spacing between parsed demo frames in ticks.
*/

logger := log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)

fl := new(flag.FlagSet)
demoPathPtr := fl.String("demo", "", "Demo file `path`")
parseRatePtr := fl.Int("parserate", 128, "Parse rate, indicates spacing between ticks")
Expand Down Expand Up @@ -2757,7 +2755,14 @@ func main() {
}

// Check error
checkError(err)
if err != nil {
if errors.Is(err, dem.ErrUnexpectedEndOfDemo) {
logger.Println(err)
logger.Println("ErrUnexpectedEndOfDemo signals that the demo" +
" is incomplete / corrupt - these demos may still be useful," +
" check how far the parser got.")
}
}
}

// Function to handle errors.
Expand Down

0 comments on commit 688d4ea

Please sign in to comment.