-
-
Notifications
You must be signed in to change notification settings - Fork 450
Add comprehensive Carbon::parse() exception handling across core modules #5189
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical installation crash caused by unhandled Carbon::parse() exceptions when processing invalid or placeholder date values. The fix adds comprehensive InvalidFormatException handling to all Carbon::parse() calls across 20 files, ensuring graceful fallback behavior instead of fatal errors.
Key changes:
- Added exception handling for installation date validation in
app/Mage.phpto prevent crashes during setup - Protected all date parsing operations throughout core modules (date/time utilities, business logic, external API integrations, payment processing, and background jobs)
- Implemented consistent fallback values (null, false, current timestamp, or empty arrays) appropriate to each use case
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| app/Mage.php | Wrapped installation date check with try-catch to handle invalid placeholder dates during installation |
| app/code/core/Mage/Install/Model/Installer/Config.php | Protected replaceTmpInstallDate() against invalid date parsing |
| app/code/core/Mage/Core/Model/Date.php | Added exception handling to gmtTimestamp() and timestamp() methods with false return on failure |
| app/code/core/Mage/Core/Model/Locale.php | Protected storeTimeStamp() and isStoreDateInInterval() from invalid date formats |
| app/code/core/Mage/Core/Block/Html/Date.php | Wrapped getEscapedValue() to fallback to escaped raw value on parse failure |
| app/code/core/Mage/Eav/Model/Attribute/Data/Date.php | Added exception handling for date range validation with user-friendly error message |
| app/code/core/Mage/CatalogRule/Model/Resource/Rule.php | Protected rule date processing, silently skipping rules with invalid dates |
| app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php | Wrapped _prepareDatetimeValue() to return null on invalid dates |
| app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php | Protected validate() method from invalid datetime attributes |
| app/code/core/Mage/Api/Model/Session.php | Handled invalid dates in isSessionExpired() by treating as expired |
| app/code/core/Mage/Shipping/Block/Tracking/Popup.php | Protected delivery date/time formatting from invalid external data |
| app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php | Added exception handling for FedEx tracking response dates |
| app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php | Protected shipping day determination from invalid dates |
| app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php | Wrapped quote date calculation with loop break on failure |
| app/code/core/Mage/AdminNotification/Model/Feed.php | Protected RSS feed date parsing with fallback to current timestamp |
| app/code/core/Mage/Paypal/Model/Cert.php | Wrapped certificate timestamp parsing with fallback to current time |
| app/code/core/Mage/Paypal/Model/Express.php | Protected order authorization expiry check from invalid dates |
| app/code/core/Mage/Cron/Model/Observer.php | Added exception handling to cleanup date processing |
| app/code/core/Mage/Cron/Model/Schedule.php | Protected trySchedule() from invalid date strings |
| lib/Varien/Db/Adapter/Mysqli.php | Wrapped convertDate() and convertDateTime() to return null on invalid input |
| try { | ||
| $fromTimeStamp = Carbon::parse((string) $dateFrom)->getTimestamp(); | ||
| $toTimeStamp = Carbon::parse((string) $dateTo)->getTimestamp(); | ||
| } catch (InvalidFormatException) { | ||
| return false; | ||
| } |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try-catch block catches the InvalidFormatException and returns false, but the variables $fromTimeStamp and $toTimeStamp will not be defined if the exception is thrown. This means that line 907 will reference undefined variables when is_empty_date returns false. The code should either initialize these variables before the try-catch or check their existence before using them on lines 907-908.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
This PR is more about to adding try/catch to Carbon::parse, not only fixing the install bug :) Thats defenitly a good idea, but please wait for next date related PR. I also try to write some more tests. |
|
@copilot - revert all changes you made to the Mage.php file and keep the others. Exclude the file from this PR. |
Co-authored-by: addison74 <[email protected]>
Reverted in commit 68fd6ac. All changes to |
… Observer Co-authored-by: addison74 <[email protected]>
|



Summary of Changes
Improved date handling robustness throughout OpenMage by adding comprehensive
InvalidFormatExceptionhandling for allCarbon::parse()calls across core modules.Note: The original installation crash fix in
app/Mage.phphas been removed from this PR and will be addressed separately.Files Modified (19 files)
Installation ✅
app/code/core/Mage/Install/Model/Installer/Config.php- Protected replaceTmpInstallDate() (Rector fix: added blank line)Date/Time Core Functions ✅
app/code/core/Mage/Core/Model/Date.php- Protected gmtTimestamp() and timestamp() (PHPStan fix: updated return type)app/code/core/Mage/Core/Model/Locale.php- Protected storeTimeStamp() and isStoreDateInInterval() (Fixed: initialized variables to prevent undefined warnings)lib/Varien/Db/Adapter/Mysqli.php- Protected convertDate() and convertDateTime()app/code/core/Mage/Core/Block/Html/Date.php- Protected getEscapedValue()Business Logic ✅
app/code/core/Mage/Eav/Model/Attribute/Data/Date.php- Protected date validation (PHP CS Fixer fix: corrected indentation)app/code/core/Mage/CatalogRule/Model/Resource/Rule.php- Protected rule date processing (Rector fix: added blank line)app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php- Protected _prepareDatetimeValue()app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php- Protected validate()app/code/core/Mage/Api/Model/Session.php- Protected isSessionExpired()External Data Sources ✅
app/code/core/Mage/Shipping/Block/Tracking/Popup.php- Protected delivery date formattingapp/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php- Protected tracking dates (Rector fix: added blank lines)app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php- Protected _determineShippingDay()app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php- Protected _getQuotes() (Rector fix: added blank line)app/code/core/Mage/AdminNotification/Model/Feed.php- Protected RSS date parsingPayment & Background Jobs ✅
app/code/core/Mage/Paypal/Model/Cert.php- Protected getCertPath() (Rector fix: added blank line)app/code/core/Mage/Paypal/Model/Express.php- Protected canCapture()app/code/core/Mage/Cron/Model/Observer.php- Protected cleanup date handling (Fixed: improved logic to check empty dates before parsing)app/code/core/Mage/Cron/Model/Schedule.php- Protected trySchedule()Quality Checks ✅
false|intImpact
✅ Prevents crashes from malformed dates in external API responses (shipping carriers, RSS feeds, etc.)
✅ More robust date handling throughout the application
✅ Improved cron history cleanup logic to properly handle malformed date records
✅ No breaking changes - all changes are backwards compatible
Scope Note
This PR focuses on adding comprehensive exception handling for
Carbon::parse()calls throughout the codebase. The original installation crash issue mentioned in the linked issue will be addressed in a separate PR with appropriate tests.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.