From 4497b06ecbc94a885414e5dc65f421385e35b848 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 30 Aug 2024 17:25:01 +0530 Subject: [PATCH] refactor: handle connection error gracefully in antiCheatTest --- internal/anti_cheat.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/anti_cheat.go b/internal/anti_cheat.go index 6d10a48b..3566fe7d 100644 --- a/internal/anti_cheat.go +++ b/internal/anti_cheat.go @@ -14,6 +14,7 @@ func antiCheatTest(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger b := redis_executable.NewRedisExecutable(stageHarness) + // If we can't run the executable, it must be an internal error. if err := b.Run(); err != nil { logger.Criticalf("CodeCrafters internal error. Error instantiating executable: %v", err) logger.Criticalf("Try again? Please contact us at hello@codecrafters.io if this persists.") @@ -21,11 +22,9 @@ func antiCheatTest(stageHarness *test_case_harness.TestCaseHarness) error { } client, err := instrumented_resp_connection.NewFromAddr(logger, "localhost:6379", "replica") + // If we are unable to connect to the redis server, it is okay to skip anti-cheat in that case, their server must not be working. if err != nil { - logFriendlyError(logger, err) - logger.Criticalf("CodeCrafters internal error. Error creating connection to redis server: %v", err) - logger.Criticalf("Try again? Please contact us at hello@codecrafters.io if this persists.") - return fmt.Errorf("anti-cheat (ac1) failed") + return nil } defer client.Close()