Commit 300568d2 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Fix error handling when attempting to write records to a tournament that does not exist.

parent 49ba6f76
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
### Fixed
- Fix creator id being read from the wrong argument in JS runtime group update function.
- Fix max count being incorrectly validated in group update JS runtime function.
- Fix error handling when attempting to write records to a tournament that does not exist.

## [3.4.0] - 2021-07-08
### Added
+5 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ func TournamentCreate(ctx context.Context, logger *zap.Logger, cache Leaderboard

func TournamentDelete(ctx context.Context, cache LeaderboardCache, rankCache LeaderboardRankCache, scheduler LeaderboardScheduler, leaderboardId string) error {
	leaderboard := cache.Get(leaderboardId)
	if leaderboard == nil {
	if leaderboard == nil || !leaderboard.IsTournament() {
		// If it does not exist treat it as success.
		return nil
	}
@@ -366,6 +366,9 @@ func TournamentRecordsList(ctx context.Context, logger *zap.Logger, db *sql.DB,

func TournamentRecordWrite(ctx context.Context, logger *zap.Logger, db *sql.DB, leaderboardCache LeaderboardCache, rankCache LeaderboardRankCache, tournamentId string, ownerId uuid.UUID, username string, score, subscore int64, metadata string, overrideOperator api.Operator) (*api.LeaderboardRecord, error) {
	leaderboard := leaderboardCache.Get(tournamentId)
	if leaderboard == nil || !leaderboard.IsTournament() {
		return nil, ErrTournamentNotFound
	}

	nowTime := time.Now().UTC()
	nowUnix := nowTime.Unix()
@@ -581,7 +584,7 @@ func TournamentRecordWrite(ctx context.Context, logger *zap.Logger, db *sql.DB,

func TournamentRecordsHaystack(ctx context.Context, logger *zap.Logger, db *sql.DB, leaderboardCache LeaderboardCache, rankCache LeaderboardRankCache, leaderboardId string, ownerId uuid.UUID, limit int, expiryOverride int64) ([]*api.LeaderboardRecord, error) {
	leaderboard := leaderboardCache.Get(leaderboardId)
	if leaderboard == nil {
	if leaderboard == nil || !leaderboard.IsTournament() {
		return nil, ErrLeaderboardNotFound
	}