Skip to content

Setting: wrapErrors ‚Äč

wrapErrors [yes,no] is a boolean setting and can be defined as CLI argument, converter comment or method comment. This setting is inheritable.

Enable wrapErrors to instruct goverter to wrap errors returned by extend methods. Wrapped errors will contain troubleshooting information like the target struct's field name related to this error.

go
package example

// goverter:converter
// goverter:extend strconv:Atoi
// goverter:wrapErrors
type Converter interface {
	Convert(source Input) (Output, error)
}

type Input struct {
	PostalCode string
}
type Output struct {
	PostalCode int
}
go
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
//go:build !goverter

package generated

import (
	"fmt"
	wraperrors "github.com/jmattheis/goverter/example/wrap-errors"
	"strconv"
)

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source wraperrors.Input) (wraperrors.Output, error) {
	var exampleOutput wraperrors.Output
	xint, err := strconv.Atoi(source.PostalCode)
	if err != nil {
		return exampleOutput, fmt.Errorf("error setting field PostalCode: %w", err)
	}
	exampleOutput.PostalCode = xint
	return exampleOutput, nil
}