From e575315275481f5f339455d1b9f40c29667c842b Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Tue, 21 Sep 2021 18:44:03 -0400 Subject: [PATCH] Add debug log for nil referencedPost (#18437) * add debug log for nil post * add post id for context * log other vars that may be nil * change from Warn to Debug --- app/post_metadata.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/post_metadata.go b/app/post_metadata.go index 0151b0b370..2d54d68bed 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -5,6 +5,7 @@ package app import ( "bytes" + "errors" "fmt" "image" "io" @@ -490,16 +491,34 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool return nil, nil, nil, appErr } + if referencedPost == nil { + msg := "Referenced post is nil" + mlog.Debug(msg, mlog.String("post_id", referencedPostID)) + return nil, nil, nil, errors.New(msg) + } + referencedChannel, appErr := a.GetChannel(referencedPost.ChannelId) if appErr != nil { return nil, nil, nil, appErr } + if referencedChannel == nil { + msg := "Referenced channel is nil" + mlog.Debug(msg, mlog.String("channel_id", referencedPost.ChannelId)) + return nil, nil, nil, errors.New(msg) + } + referencedTeam, appErr := a.GetTeam(referencedChannel.TeamId) if appErr != nil { return nil, nil, nil, appErr } + if referencedTeam == nil { + msg := "Referenced team is nil" + mlog.Debug(msg, mlog.String("team_id", referencedChannel.TeamId)) + return nil, nil, nil, errors.New(msg) + } + permalink = &model.Permalink{PreviewPost: model.NewPreviewPost(referencedPost, referencedTeam, referencedChannel)} } else {