Commit 5b42bb58 by Marcus Efraimsson Committed by GitHub

Telegram: Check error before adding defer close of image (#20331)

Properly handles file opening error and returns before deferring 
close of file.

Fixes #20156
parent 9e049900
......@@ -137,6 +137,10 @@ func (tn *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.EvalCo
var err error
imageFile, err = os.Open(evalContext.ImageOnDiskPath)
if err != nil {
return nil, err
}
defer func() {
err := imageFile.Close()
if err != nil {
......@@ -144,10 +148,6 @@ func (tn *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.EvalCo
}
}()
if err != nil {
return nil, err
}
ruleURL, err := evalContext.GetRuleURL()
if err != nil {
return nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment