From db38226757af0451dee087b240fdf361b70e152c Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 28 Oct 2024 00:24:44 +0100 Subject: [PATCH] fix: division by zero for PoolHandler (fixing #14) --- pool.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pool.go b/pool.go index 1e82fcf..dc40de1 100644 --- a/pool.go +++ b/pool.go @@ -41,6 +41,10 @@ func (h *PoolHandler) Enabled(ctx context.Context, l slog.Level) bool { // Implements slog.Handler func (h *PoolHandler) Handle(ctx context.Context, r slog.Record) error { + if len(h.handlers) == 0 { + return nil + } + // round robin rand := h.randSource.Int63() % int64(len(h.handlers)) handlers := append(h.handlers[rand:], h.handlers[:rand]...)