feat: better convert usage

This commit is contained in:
2026-02-05 22:28:53 -05:00
parent 53042ea26d
commit b47a3a3acb
3 changed files with 15 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package cli
import (
"fmt"
"reflect"
"git.maximhutz.com/max/lambda/pkg/codec"
)
@@ -29,7 +30,9 @@ func (c convertedMarshaler[T]) Decode(s string) (Repr, error) {
func (c convertedMarshaler[T]) Encode(r Repr) (string, error) {
t, ok := r.Data().(T)
if !ok {
return "", fmt.Errorf("could not parse '%v' as 'string'", t)
dataType := reflect.TypeOf(r.Data())
allowedType := reflect.TypeFor[T]()
return "", fmt.Errorf("marshaler for '%s' cannot parse '%s'", allowedType, dataType)
}
return c.codec.Encode(t)