From 6f0f40697dd04bda82700cb51d1a1fb40b2d6580 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 15 Jul 2024 14:59:50 -0500 Subject: [PATCH] chore(pattern): Return an error when plaintext parsing encounters an unknown char --- internal/pattern/pattern.go | 7 ++++--- internal/pattern/plaintext.go | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/pattern/pattern.go b/internal/pattern/pattern.go index 68cfb81..405f57b 100644 --- a/internal/pattern/pattern.go +++ b/internal/pattern/pattern.go @@ -30,9 +30,10 @@ func FormatStrings() []string { } var ( - ErrInvalidHeader = errors.New("invalid header") - ErrUnknownExtension = errors.New("unknown pattern extension") - ErrPatternTooBig = errors.New("pattern too big") + ErrInvalidHeader = errors.New("invalid header") + ErrUnknownExtension = errors.New("unknown pattern extension") + ErrPatternTooBig = errors.New("pattern too big") + ErrUnexpectedCharacter = errors.New("unexpected character") ) const ( diff --git a/internal/pattern/plaintext.go b/internal/pattern/plaintext.go index 9766649..b639a40 100644 --- a/internal/pattern/plaintext.go +++ b/internal/pattern/plaintext.go @@ -40,6 +40,8 @@ func UnmarshalPlaintext(r io.Reader) (Pattern, error) { case 'O', '*': tileLine[x] = 1 x++ + default: + return pattern, fmt.Errorf("plaintext: %w: %q in line %q", ErrUnexpectedCharacter, string(b), line) } } if len(tileLine) > largest {