From 4f8672c9ab290c752ce97da4008b407b19111ff7 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Sun, 16 Mar 2025 17:44:33 -0700 Subject: [PATCH] internal/cm: change error type from struct{string} This is a temporary fix until cm@v0.2.2 is released, and package internal/cm and internal/wasi can be regenerated. See #4810 for more information. --- src/internal/cm/case.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/internal/cm/case.go b/src/internal/cm/case.go index fa212bb0c..2ca7c28da 100644 --- a/src/internal/cm/case.go +++ b/src/internal/cm/case.go @@ -9,7 +9,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te if len(cases) <= linearScanThreshold { return func(v *T, text []byte) error { if len(text) == 0 { - return errEmpty + return &emptyTextError{} } s := string(text) for i := 0; i < len(cases); i++ { @@ -18,7 +18,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te return nil } } - return errNoMatchingCase + return &noMatchingCaseError{} } } @@ -29,11 +29,11 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te return func(v *T, text []byte) error { if len(text) == 0 { - return errEmpty + return &emptyTextError{} } c, ok := m[string(text)] if !ok { - return errNoMatchingCase + return &noMatchingCaseError{} } *v = c return nil @@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te const linearScanThreshold = 16 -var ( - errEmpty = &stringError{"empty text"} - errNoMatchingCase = &stringError{"no matching case"} -) +type emptyTextError struct{} -type stringError struct { - err string -} +func (*emptyTextError) Error() string { return "empty text" } -func (err *stringError) Error() string { - return err.err -} +type noMatchingCaseError struct{} + +func (*noMatchingCaseError) Error() string { return "no matching case" }