refactor(model): use log.Fatal for Encode128 contract guard per project convention

This commit is contained in:
Deluan 2026-07-19 22:52:54 -04:00
parent da4da4e749
commit 4f279e4866
2 changed files with 3 additions and 5 deletions

View File

@ -6,6 +6,8 @@ import (
"fmt"
"math/big"
"strings"
"github.com/navidrome/navidrome/log"
)
func NewRandom() string {
@ -17,7 +19,7 @@ func NewRandom() string {
// Encode128 renders a 16-byte value as the canonical 22-char zero-padded base62 id.
func Encode128(b []byte) string {
if len(b) != 16 {
panic(fmt.Sprintf("id.Encode128: expected 16 bytes, got %d", len(b)))
log.Fatal("Encode128: expected 16 bytes", "got", len(b))
}
return fmt.Sprintf("%022s", new(big.Int).SetBytes(b).Text(62))
}

View File

@ -22,10 +22,6 @@ var _ = Describe("Encode128/Decode128", func() {
Expect(id.Decode128(s)).To(Equal(b))
})
It("panics on non-16-byte input", func() {
Expect(func() { id.Encode128(make([]byte, 15)) }).To(Panic())
})
It("rejects invalid input", func() {
_, err := id.Decode128("short")
Expect(err).To(HaveOccurred())