Skip to content

Commit

Permalink
Merge pull request #163 from codecrafters-io/update-anti-cheat
Browse files Browse the repository at this point in the history
Refactor: Handle connection error gracefully in antiCheatTest
  • Loading branch information
rohitpaulk authored Aug 30, 2024
2 parents 6654c27 + 4497b06 commit acd81ae
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/anti_cheat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ 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.")
return fmt.Errorf("anti-cheat (ac1) failed")
}

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()

Expand Down

0 comments on commit acd81ae

Please sign in to comment.