Giter Site home page Giter Site logo

go-fishbowl's People

Contributors

dependabot[bot] avatar jhammy avatar nneibaue avatar tifmoe avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nneibaue

go-fishbowl's Issues

GetGame called before gameID exists

When starting a new game (on the home page, after typing in team names), the following error always shows up:

image

This is being caught here (line 70):

func (c conn) GetGame(gameID string) (game *Game, err error) {
data, err := c.Client.Get(gameID).Result()
if err != nil {
fmt.Printf("Game %s does not exist: %v\n", gameID, err)
return game, err
}

After doing some digging, I found that in Repository.SaveNewGame, GetGame is called before the gameID is set:

func (c conn) SaveNewGame(gameID, team1, team2 string) error {
exists, _ := c.GetGame(gameID)
if exists != nil {
err := fmt.Errorf("failed to save: game %s already exists", gameID)
return err
}
game, err := json.Marshal(Game{
ID: gameID,
Teams: Teams{
Team1: Team{
Name: team1,
},
Team2: Team{
Name: team2,
},
},
})
if err != nil {
fmt.Printf("Error marshalling new game %s: %v\n", gameID, err)
return err
}
err = c.Client.Set(gameID, game, ttl).Err()
if err != nil {
fmt.Printf("Error saving game %s: %v\n", gameID, err)
return err
}
return nil
}

GetGame is trying to access GameID here:

exists, _ := c.GetGame(gameID)

but it is not being set util here:

err = c.Client.Set(gameID, game, ttl).Err()

.

GetGame is called again when the GamePage is loaded here:

componentDidMount() {
const { params: { gameId } } = this.props.match;
axios({
method: 'get',
url: `/v1/api/game/${gameId}`,
timeout: 4000, // 4 seconds timeout
})

But the error no longer prints to the console because by then the gameID is already set. So we have a situation where GetGame is being called twice in a row with different behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.