src.common.utils

Common utilities for error handling and validation across the Wordle Solver.

Functions

calculate_success_metrics(guesses_history, won)

Calculate various success metrics from guess history.

format_guess_history(guesses_history)

Format guess history for display purposes.

safe_execute([operation_name])

Decorator to safely execute operations and handle common exceptions.

validate_result_pattern(result[, ...])

Validate result pattern ensuring it contains only valid color codes.

validate_word_input(word[, word_length])

Validate word input ensuring it meets Wordle requirements.

src.common.utils.validate_word_input(word, word_length=5)[source]

Validate word input ensuring it meets Wordle requirements.

Parameters:
  • word (str) – The word to validate

  • word_length (int) – Expected word length (default: 5)

Return type:

str

Returns:

The validated and normalized word (uppercase)

Raises:

InvalidGuessError – If the word is invalid

src.common.utils.validate_result_pattern(result, expected_length=5)[source]

Validate result pattern ensuring it contains only valid color codes.

Parameters:
  • result (str) – The result pattern to validate

  • expected_length (int) – Expected pattern length (default: 5)

Return type:

str

Returns:

The validated and normalized result pattern (uppercase)

Raises:

InvalidResultError – If the result pattern is invalid

src.common.utils.safe_execute(operation_name='operation')[source]

Decorator to safely execute operations and handle common exceptions.

Parameters:

operation_name (str) – Name of the operation for error messages

src.common.utils.format_guess_history(guesses_history)[source]

Format guess history for display purposes.

Parameters:

guesses_history (list) – List of [guess, result, strategy] tuples

Return type:

str

Returns:

Formatted string representation of the guess history

src.common.utils.calculate_success_metrics(guesses_history, won)[source]

Calculate various success metrics from guess history.

Parameters:
  • guesses_history (list) – List of guess attempts

  • won (bool) – Whether the game was won

Return type:

dict

Returns:

Dictionary containing success metrics