Problem/Motivation
I was trying to debug why I was getting an Exception when accepting a Payment on an Order for a different currency.
My error log looked like:
"NOTICE: PHP message: Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "" at /var/www/html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php line 786"
I not only had to dig down to see what SqlContentEntityStorage was doing, but had to break on the original exception trace to figure out that it was Price that was throwing the CurrencyMismatchException. It was a bit more effort than that as I also started digging through the issue queue to figure out why the exception could be thrown (understood now).
It would improve developer experience to provide messages for all exceptions. I also noticed empty exceptions thrown for InvalidArgumentException.
Proposed resolution
Provide error messages in exceptions or provide a default message in the initialization method of the exception class?
Remaining tasks
- Patch review
Comment | File | Size | Author |
---|---|---|---|
#6 | 3027073-6-price-exception-messages.patch | 2.69 KB | bojanz |
#4 | commerce-3027073-add-exception-messages-4.patch | 831 bytes | mradcliffe |
|
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedThis is concerning. We never expected core to eat any of our exceptions (and convert them into something obscure-sounding).
We generally have a policy of always providing exception messages, looks like the Price object is the only one going against that. No reason not to fix it.
Comment #3
bojanz CreditAttribution: bojanz at Centarro commentedSo, let's clarify.
We need to fix assertCurrencyCodeFormat and assertSameCurrency.
Comment #4
mradcliffeYeah, I agree that it's a bit concerning with respect to core behavior.
Here's a patch. Since it's only adding strings I didn't bother with any additional test assertions.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedIt would be great for debugging if we included the known data in the message.
1) "Invalid currency code USDF"
2)
"The provided prices (10 USD, 20 EUR) have mismatched currencies"
or
"The provided prices have mismatched currencies (USD, EUR)"
Comment #6
bojanz CreditAttribution: bojanz at Centarro commentedLet's wrap this issue up.
Attaching patch that addresses #5.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedComment #9
bojanz CreditAttribution: bojanz at Centarro commentedCommitted.