package matcher

import (
	. "github.com/onsi/gomega"
)

func Try(xs ...interface{}) interface{} {
	if len(xs) == 0 {
		return nil
	}
	if err, ok := xs[len(xs)-1].(error); ok && err != nil {
		// Set offset to 1 to track the code location of the real assertion statement,
		// so that gomega can show the proper stack trace when the assertion fails.
		ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
	}
	return xs[0]
}
