Skip to content

Commit

Permalink
Don't panic on runBotAction error. Better logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogappa committed Jul 22, 2024
1 parent faaa10a commit 4cf8615
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions main_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ func trucoRunAction(this js.Value, p []js.Value) interface{} {
}

func trucoBotRunAction(this js.Value, p []js.Value) interface{} {
action := bot.ChooseAction(state.ToClientGameState(1))
fmt.Println("Action chosen by bot:", action)
if !state.IsGameEnded {
action := bot.ChooseAction(state.ToClientGameState(1))
fmt.Println("Action chosen by bot:", action)

err := state.RunAction(action)
if err != nil {
panic(fmt.Errorf("running action: %w", err))
err := state.RunAction(action)
if err != nil {
panic(fmt.Errorf("running action: %w", err))
}
}

nbs, err := json.Marshal(state.ToClientGameState(0))
if err != nil {
panic(fmt.Errorf("marshalling game state: %w", err))
Expand Down
2 changes: 1 addition & 1 deletion truco/truco.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func DeserializeAction(bs []byte) (Action, error) {
case REVEAL_ENVIDO_SCORE:
action = &ActionRevealEnvidoScore{}
default:
return nil, fmt.Errorf("unknown action type %v", actionName.Name)
return nil, fmt.Errorf("unknown action: [%v]", string(bs))
}

err = json.Unmarshal(bs, action)
Expand Down

0 comments on commit 4cf8615

Please sign in to comment.