chore: improve errors and tests

This commit is contained in:
2024-03-23 21:05:57 +00:00
parent 5247fbd90b
commit ccc3668fa2
7 changed files with 262 additions and 30 deletions

View File

@@ -104,6 +104,10 @@ func Render(w io.Writer, format string, v any) error {
func New(formats ...string) (*Renderer, error) {
renderers := map[string]FormatRenderer{}
if len(formats) == 0 {
return nil, fmt.Errorf("%w: no formats specified", Err)
}
for _, format := range formats {
switch format {
case "binary":
@@ -128,7 +132,7 @@ func New(formats ...string) (*Renderer, error) {
func MustNew(formats ...string) *Renderer {
r, err := New(formats...)
if err != nil {
panic(err)
panic(err.Error())
}
return r