Fatal error when trying to add transaction to a non-existing card

Created on 17 March 2025, 16 days ago

Problem/Motivation

When trying to create a Transaction from the Add transaction form and the entered code is not valid, system throws a fatal error WSOD instead of an error indicating that code is not valid:

Error: Call to a member function getBalance() on null in Drupal\commerce_giftcard\Plugin\Validation\Constraint\GiftcardTransactionValidAmountValidator->validate() (line 38 of modules/contrib/commerce_giftcard/src/Plugin/Validation/Constraint/GiftcardTransactionValidAmountValidator.php).

Steps to reproduce

Create a few giftcards
Visit /admin/commerce/giftcards/add-transaction
Enter an invalid giftcard code i nthe autocomplete field
Submit the form
Get the unexpected fatal error instead of just a simple error message.

Proposed resolution

Improve error handling

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇪🇸Spain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @plopesc
  • 🇪🇸Spain plopesc Valladolid

    Created MR

  • Pipeline finished with Failed
    16 days ago
    Total: 272s
    #450450
  • 🇨🇴Colombia juandhr Manizales

    I have reviewed and tested the changes, and they work as expected.

    • The system no longer throws a fatal error when entering an invalid gift card code in the Add Transaction form.
    • Instead, the validation properly detects when the code does not exist and displays an appropriate error message.
    • Functionality was tested in a clean Drupal [version] environment, and no issues were found.

    Since the validation is now correctly handling non-existing gift card codes and preventing fatal errors, I am marking this as RTBC.

Production build 0.71.5 2024