From de17aeac5690b0dd4e1bde915f87b555a5ddd0e4 Mon Sep 17 00:00:00 2001 From: Eli Burch Date: Sat, 7 Feb 2026 10:23:32 -0800 Subject: [PATCH] Replace panic with error return --- encoder.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/encoder.go b/encoder.go index 582cbcf..73803ba 100644 --- a/encoder.go +++ b/encoder.go @@ -116,7 +116,9 @@ func (e *encoder) Encode(byts []byte) (*binary.Binary, error) { } // fill and _defaultPadding bits - e.breakUpInto8bit() + if err := e.breakUpInto8bit(); err != nil { + return nil, err + } return e.dst, nil } @@ -178,7 +180,7 @@ func (e *encoder) encodeByte() { } // Break Up into 8-bit Codewords and Add Pad Bytes if Necessary -func (e *encoder) breakUpInto8bit() { +func (e *encoder) breakUpInto8bit() error { // fill ending code (max 4bit) // depends on max capacity of current version and EC level maxCap := e.version.NumTotalCodewords() * 8 @@ -187,7 +189,7 @@ func (e *encoder) breakUpInto8bit() { "wrong version(%d) cap(%d bits) and could not contain all bits: %d bits", e.version.Ver, maxCap, e.dst.Len(), ) - panic(err) + return err } else if less < 4 { e.dst.AppendNumBools(less, false) } else { @@ -211,6 +213,7 @@ func (e *encoder) breakUpInto8bit() { } } } + return nil } // 字符计数指示符位长字典