Call to a member function getCode() on null

Created on 10 January 2024, 11 months ago

This line caused a NULL pointer exception for a client when they tried to capture a Vipps payment: https://git.drupalcode.org/project/commerce_vipps/-/blob/8.x-4.x/src/Plu...

Because the code failed there the exception from Vipps was never logged so I don't know what it was, but it's clear from the API that $exception->getError() can return NULL, so the code needs to be rewritten so that it ensures we have an error before trying to read it's error code.

My assumption is that not having an error is the same as having the wrong error code.

I'll attach a patch with my proposed change shortly.

🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇳🇴Norway TwiiK

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

Comments & Activities

  • Issue created by @TwiiK
  • 🇳🇴Norway TwiiK

    Patch attached.

    Edit: I see merge requests are recommended now, but I have no idea how to do that. Maybe in the future...

  • Status changed to Needs review 11 months ago
  • 🇳🇴Norway TwiiK

    I realized PHPStorm rewrote the error code comparison to be strict, but getCode() apparently returns a string so I reverted that change, and attached an updated patch.

Production build 0.71.5 2024