From cbfc14b2b4ff39ff7d1e4b7875d333f4d8a5942a Mon Sep 17 00:00:00 2001 From: Julien Tant <785518+JulienTant@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:41:40 -0700 Subject: [PATCH] [MM-52922] Fix a possible nil call to subscription.LastInvoice (#23540) Co-authored-by: Mattermost Build --- server/channels/app/cloud.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/channels/app/cloud.go b/server/channels/app/cloud.go index a40b22da37..5fdc1e5e26 100644 --- a/server/channels/app/cloud.go +++ b/server/channels/app/cloud.go @@ -198,12 +198,17 @@ func (a *App) SendUpgradeConfirmationEmail(isYearly bool) *model.AppError { embeddedFiles := make(map[string]io.Reader) if isYearly { - pdf, filename, pdfErr := a.Cloud().GetInvoicePDF("", subscription.LastInvoice.ID) - if pdfErr != nil { - a.Log().Error("Error retrieving the invoice for subscription id", mlog.String("subscription", subscription.ID), mlog.Err(pdfErr)) + lastInvoice := subscription.LastInvoice + if lastInvoice == nil { + a.Log().Error("Last invoice not defined for the subscription", mlog.String("subscription", subscription.ID)) } else { - embeddedFiles = map[string]io.Reader{ - filename: bytes.NewReader(pdf), + pdf, filename, pdfErr := a.Cloud().GetInvoicePDF("", lastInvoice.ID) + if pdfErr != nil { + a.Log().Error("Error retrieving the invoice for subscription id", mlog.String("subscription", subscription.ID), mlog.Err(pdfErr)) + } else { + embeddedFiles = map[string]io.Reader{ + filename: bytes.NewReader(pdf), + } } } }