package mapstructure

import (
	
	
	
	
	
	
	
	
)

// Error interface is implemented by all errors emitted by mapstructure.
//
// Use [errors.As] to check if an error implements this interface.
type Error interface {
	error

	mapstructure()
}

// DecodeError is a generic error type that holds information about
// a decoding error together with the name of the field that caused the error.
type DecodeError struct {
	name string
	err  error
}

func newDecodeError( string,  error) *DecodeError {
	return &DecodeError{
		name: ,
		err:  ,
	}
}

func ( *DecodeError) () string {
	return .name
}

func ( *DecodeError) () error {
	return .err
}

func ( *DecodeError) () string {
	return fmt.Sprintf("'%s' %s", .name, .err)
}

func (*DecodeError) () {}

// ParseError is an error type that indicates a value could not be parsed
// into the expected type.
type ParseError struct {
	Expected reflect.Value
	Value    any
	Err      error
}

func ( *ParseError) () string {
	return fmt.Sprintf("cannot parse value as '%s': %s", .Expected.Type(), .Err)
}

func (*ParseError) () {}

// UnconvertibleTypeError is an error type that indicates a value could not be
// converted to the expected type.
type UnconvertibleTypeError struct {
	Expected reflect.Value
	Value    any
}

func ( *UnconvertibleTypeError) () string {
	return fmt.Sprintf(
		"expected type '%s', got unconvertible type '%s'",
		.Expected.Type(),
		reflect.TypeOf(.Value),
	)
}

func (*UnconvertibleTypeError) () {}

func wrapStrconvNumError( error) error {
	if  == nil {
		return nil
	}

	if ,  := .(*strconv.NumError);  {
		return &strconvNumError{Err: }
	}

	return 
}

type strconvNumError struct {
	Err *strconv.NumError
}

func ( *strconvNumError) () string {
	return "strconv." + .Err.Func + ": " + .Err.Err.Error()
}

func ( *strconvNumError) () error { return .Err }

func wrapUrlError( error) error {
	if  == nil {
		return nil
	}

	if ,  := .(*url.Error);  {
		return &urlError{Err: }
	}

	return 
}

type urlError struct {
	Err *url.Error
}

func ( *urlError) () string {
	return fmt.Sprintf("%s", .Err.Err)
}

func ( *urlError) () error { return .Err }

func wrapNetParseError( error) error {
	if  == nil {
		return nil
	}

	if ,  := .(*net.ParseError);  {
		return &netParseError{Err: }
	}

	return 
}

type netParseError struct {
	Err *net.ParseError
}

func ( *netParseError) () string {
	return "invalid " + .Err.Type
}

func ( *netParseError) () error { return .Err }

func wrapTimeParseError( error) error {
	if  == nil {
		return nil
	}

	if ,  := .(*time.ParseError);  {
		return &timeParseError{Err: }
	}

	return 
}

type timeParseError struct {
	Err *time.ParseError
}

func ( *timeParseError) () string {
	if .Err.Message == "" {
		return fmt.Sprintf("parsing time as %q: cannot parse as %q", .Err.Layout, .Err.LayoutElem)
	}

	return "parsing time " + .Err.Message
}

func ( *timeParseError) () error { return .Err }

func wrapNetIPParseAddrError( error) error {
	if  == nil {
		return nil
	}

	if  := .Error(); strings.HasPrefix(, "ParseAddr") {
		 := strings.Split(, ": ")

		return fmt.Errorf("ParseAddr: %s", [len()-1])
	}

	return 
}

func wrapNetIPParseAddrPortError( error) error {
	if  == nil {
		return nil
	}

	 := .Error()
	if strings.HasPrefix(, "invalid port ") {
		return errors.New("invalid port")
	} else if strings.HasPrefix(, "invalid ip:port ") {
		return errors.New("invalid ip:port")
	}

	return 
}

func wrapNetIPParsePrefixError( error) error {
	if  == nil {
		return nil
	}

	if  := .Error(); strings.HasPrefix(, "netip.ParsePrefix") {
		 := strings.Split(, ": ")

		return fmt.Errorf("netip.ParsePrefix: %s", [len()-1])
	}

	return 
}

func wrapTimeParseDurationError( error) error {
	if  == nil {
		return nil
	}

	 := .Error()
	if strings.HasPrefix(, "time: unknown unit ") {
		return errors.New("time: unknown unit")
	} else if strings.HasPrefix(, "time: ") {
		 := strings.LastIndex(, " ")

		return errors.New([:])
	}

	return 
}

func wrapTimeParseLocationError( error) error {
	if  == nil {
		return nil
	}
	 := .Error()
	if strings.Contains(, "unknown time zone") || strings.HasPrefix(, "time: unknown format") {
		return fmt.Errorf("invalid time zone format: %w", )
	}

	return 
}