Skip to content

Commit 45b2a33

Browse files
authored
Merge pull request #25 from gijswijs/hexn-print-nil
btclog: handle nil slices in HexN gracefully
2 parents 6090e87 + 5b03062 commit 45b2a33

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

v2/attrs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func Hex2(key string, value []byte) slog.Attr {
3232
// HexN is a convenience function for hex-encoded log attributes which prints
3333
// a maximum of n bytes.
3434
func HexN(key string, value []byte, n uint) slog.Attr {
35+
// Handle nil slice gracefully.
36+
if value == nil {
37+
return slog.String(key, "<nil>")
38+
}
39+
3540
if len(value) <= int(n) {
3641
return slog.String(key, hex.EncodeToString(value))
3742
}

0 commit comments

Comments
 (0)