From 08909b6b66dac99b328bda4dc323d9a50a54fbe8 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 14 Feb 2026 20:43:55 +0000 Subject: [PATCH] log at warn level invalid bps, channel values. inform user of default value. --- option.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/option.go b/option.go index bb00187..80fd97d 100644 --- a/option.go +++ b/option.go @@ -19,18 +19,37 @@ func WithRateLimit(ratelimit time.Duration) Option { // WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet. func WithBPSOpt(bps int) Option { return func(vt *VbanTxt) { + defaultBps := BpsOpts[vt.packet.bpsIndex] + bpsIndex := indexOf(BpsOpts, bps) if bpsIndex == -1 { - log.Warnf("invalid bps value %d, expected one of %v, defaulting to 0", bps, BpsOpts) + log.Warnf( + "invalid bps value %d, expected one of %v, defaulting to %d", + bps, + BpsOpts, + defaultBps, + ) return } - vt.packet.bpsIndex = bpsIndex + if bpsIndex > 255 { + log.Warnf("bps index %d too large for uint8, defaulting to %d", bpsIndex, defaultBps) + return + } + vt.packet.bpsIndex = uint8(bpsIndex) } } // WithChannel is a functional option to set the channel for {VbanTxt}.packet. func WithChannel(channel int) Option { return func(vt *VbanTxt) { - vt.packet.channel = channel + if channel < 0 || channel > 255 { + log.Warnf( + "channel value %d out of range [0,255], defaulting to %d", + channel, + vt.packet.channel, + ) + return + } + vt.packet.channel = uint8(channel) } }