From 946d9888d6bdbc2661f90fc92feb311a4539eba5 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 23 Oct 2024 11:16:09 +0200 Subject: [PATCH] Refactor error handling in Base64LineBreaker Switched ErrNoOutWriter from a string constant to an error object for improved error handling consistency. This change enhances clarity and reduces the risk of error handling inconsistencies in the future. --- b64linebreaker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/b64linebreaker.go b/b64linebreaker.go index cc83973..abc356a 100644 --- a/b64linebreaker.go +++ b/b64linebreaker.go @@ -13,8 +13,8 @@ import ( // in encoding processes. var newlineBytes = []byte(SingleNewLine) -// ErrNoOutWriter is the error message returned when no io.Writer is set for Base64LineBreaker. -const ErrNoOutWriter = "no io.Writer set for Base64LineBreaker" +// ErrNoOutWriter is the error returned when no io.Writer is set for Base64LineBreaker. +var ErrNoOutWriter = errors.New("no io.Writer set for Base64LineBreaker") // Base64LineBreaker handles base64 encoding with the insertion of new lines after a certain number // of characters. @@ -44,7 +44,7 @@ type Base64LineBreaker struct { // - err: An error if one occurred during the write operation. func (l *Base64LineBreaker) Write(data []byte) (numBytes int, err error) { if l.out == nil { - err = errors.New(ErrNoOutWriter) + err = ErrNoOutWriter return } if l.used+len(data) < MaxBodyLength {