logging: report issues in rbdImage.DEKStore API with stacks

It helps to get a stack trace when debugging issues. Certain things are
considered bugs in the code (like missing attributes in a struct), and
might cause a panic in certain occasions.

In this case, a missing string will not panic, but the behaviour will
also not be correct (DEKs getting encrypted, but unable to decrypt).
Clearly logging this as a BUG is probably better than calling panic().

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-04-09 14:04:38 +02:00
committed by mergify[bot]
parent 35d58a7d5a
commit 8b8480017b
2 changed files with 31 additions and 5 deletions

View File

@ -22,6 +22,7 @@ import (
"fmt"
"math"
"os"
"runtime"
"strconv"
"strings"
"time"
@ -333,3 +334,12 @@ func getKeys(m map[string]interface{}) []string {
return keys
}
// CallStack returns the stack of the calls in the current goroutine. Useful
// for debugging or reporting errors. This is a friendly alternative to
// assert() or panic().
func CallStack() string {
stack := make([]byte, 2048)
_ = runtime.Stack(stack, false)
return string(stack)
}