Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Handling and Prevent Recursive Calls in Currency Conversion #365

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Jan 14, 2025

This pull request was created by Sweep to resolve the following request by @curtisdelicata:

Fix possible recursion loop as stated called by In Container.php line 1048 could be any file

Continue chatting at https://sweep-chat-demo.vercel.app/c/279998f2-27e5-4887-9874-732b688944cd.

Purpose

Enhance system stability by implementing robust error prevention and handling mechanisms for recursive calls in currency conversion and exception handling.

Description

This pull request introduces critical improvements to prevent potential infinite recursion and stack overflow scenarios:

  1. In the CurrencyService, we've implemented:

    • A static flag to prevent recursive currency conversion attempts
    • Reduced maximum recursion depth for rate calculations
    • Added a try-finally block to ensure the processing flag is always reset
    • Throw a RuntimeException if a recursive conversion is detected
  2. In the Exceptions/Handler, we've enhanced error reporting by:

    • Adding a flag to prevent recursive error handling
    • Expanding error detection to include additional recursion-related error messages
    • Implementing a try-finally block to ensure the handling flag is reset
    • Improving logging for stack overflow and recursion-related errors

Summary

  • Improved recursion prevention in CurrencyService
  • Enhanced error handling in Exceptions/Handler
  • Added safeguards against potential infinite loops
  • Reduced maximum recursion depth
  • Implemented robust error logging mechanisms

Key files modified:

  • app/Services/CurrencyService.php
  • app/Exceptions/Handler.php

@curtisdelicata curtisdelicata merged commit ac5275b into main Jan 14, 2025
1 of 4 checks passed
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