From 4cf861566b8030f66de3cee25a6fa592cc80cfad Mon Sep 17 00:00:00 2001 From: Mariano Gappa Date: Mon, 22 Jul 2024 21:30:22 +0100 Subject: [PATCH] Don't panic on runBotAction error. Better logging. --- main_wasm.go | 13 ++++++++----- truco/truco.go | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/main_wasm.go b/main_wasm.go index 43963de..dd6670e 100644 --- a/main_wasm.go +++ b/main_wasm.go @@ -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)) diff --git a/truco/truco.go b/truco/truco.go index 74b1b6e..7c15cf1 100644 --- a/truco/truco.go +++ b/truco/truco.go @@ -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)