Skip to content

Error handling#24

Merged
ptitmorceaux merged 3 commits intomainfrom
errorHandling
Nov 16, 2025
Merged

Error handling#24
ptitmorceaux merged 3 commits intomainfrom
errorHandling

Conversation

@ptitmorceaux
Copy link
Owner

This pull request improves error handling, user feedback, and memory safety throughout the codebase. The main focus is on providing clearer messages to the user when operations fail, ensuring proper cleanup of resources, and handling edge cases such as empty data files or failed allocations.

Error Handling and User Feedback Improvements:

  • Added informative messages for the user when purchases or loot attempts fail in merchant and treasure zones, and when no items are available, instead of only printing to stderr. This includes refunding the player and prompting them to continue. (code/src/jeu.c) [1] [2] [3] [4] [5] [6] [7] [8]
  • Added calls to pressEnterToContinue() after critical errors or failed allocations to ensure the user acknowledges the error before proceeding. (code/src/jeu.c, code/src/main.c) [1] [2] [3] [4]

Resource Management and Memory Safety:

  • Ensured that resources are properly freed and pointers nulled when errors occur during save loading, creation, or diver initialization, preventing use-after-free bugs. (code/src/main.c) [1] [2] [3] [4]
  • Added checks and cleanup for failed bestiary and arsenal initialization, including freeing memory and returning NULL when no creatures or groups are found in configuration files. (code/src/creatures.c, code/src/armes.c) [1] [2] [3] [4] [5]

Edge Case Handling:

  • Functions that load objects, weapons, or creatures from files now return empty lists or arsenals if the files are empty, preventing null dereferences later in the code. (code/src/objets.c, code/src/armes.c) [1] [2]

Game Flow Robustness:

  • Improved handling of game start and save loading: if running the game fails, the user is notified and prompted to continue, and errors are logged to stderr. (code/src/main.c) [1] [2] [3]

These changes collectively make the program more robust, user-friendly, and less prone to crashes or undefined behavior in error cases.

@ptitmorceaux ptitmorceaux merged commit 5957fb8 into main Nov 16, 2025
5 checks passed
@ptitmorceaux ptitmorceaux deleted the errorHandling branch November 16, 2025 17:59
ptitmorceaux added a commit that referenced this pull request Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant