From 531c3ecb7ecb6178ed9615e68417739c5242692c Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 13 Nov 2024 01:55:34 -0600 Subject: [PATCH] chore(pattern): Improve pattern load error text --- internal/pattern/pattern.go | 4 ++-- internal/pattern/plaintext.go | 2 +- internal/pattern/rle.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/pattern/pattern.go b/internal/pattern/pattern.go index 7092fff..379b64d 100644 --- a/internal/pattern/pattern.go +++ b/internal/pattern/pattern.go @@ -67,7 +67,7 @@ func Default() *Pattern { var ( ErrInvalidHeader = errors.New("invalid header") ErrUnexpectedCharacter = errors.New("unexpected character") - ErrInferFailed = errors.New("unable to infer pattern file type") + ErrDetectFailed = errors.New("unable to detect pattern file format") ) const ( @@ -163,7 +163,7 @@ func Unmarshal(r io.Reader) (*Pattern, error) { case bytes.HasPrefix(firstLine, []byte("!")), bytes.HasPrefix(firstLine, []byte(".")), bytes.HasPrefix(firstLine, []byte("O")): return UnmarshalPlaintext(bytes.NewReader(buf)) default: - return nil, ErrInferFailed + return nil, ErrDetectFailed } } diff --git a/internal/pattern/plaintext.go b/internal/pattern/plaintext.go index f09f66a..2148044 100644 --- a/internal/pattern/plaintext.go +++ b/internal/pattern/plaintext.go @@ -37,7 +37,7 @@ func UnmarshalPlaintext(r io.Reader) (*Pattern, error) { pattern.Tree.Set(p, 1) p.X++ default: - return nil, fmt.Errorf("plaintext: %w: %q in line %q", ErrUnexpectedCharacter, string(b), line) + return nil, fmt.Errorf("plaintext: %w: %q in line: %q", ErrUnexpectedCharacter, string(b), line) } } p.X = 0 diff --git a/internal/pattern/rle.go b/internal/pattern/rle.go index a672082..d85fa5b 100644 --- a/internal/pattern/rle.go +++ b/internal/pattern/rle.go @@ -42,7 +42,7 @@ scan: matches := headerRe.FindStringSubmatch(scanner.Text()) if len(matches) == 0 { - return nil, fmt.Errorf("rle: %w: %s", ErrInvalidHeader, line) + return nil, fmt.Errorf("rle: %w: %q", ErrInvalidHeader, line) } var w, h int