Exemplo n.º 1
0
func TestRootCause(t *testing.T) {
	for _, test := range []struct {
		err       error
		rootCause error
	}{
		{
			err:       nil,
			rootCause: nil,
		},
		{
			err:       errors.New("msg"),
			rootCause: errors.New("msg"),
		},
		{
			err:       stacktrace.NewError("msg"),
			rootCause: errors.New("msg"),
		},
		{
			err:       stacktrace.Propagate(stacktrace.NewError("msg1"), "msg2"),
			rootCause: errors.New("msg1"),
		},
		{
			err:       customError("msg"),
			rootCause: customError("msg"),
		},
		{
			err:       stacktrace.Propagate(customError("msg1"), "msg2"),
			rootCause: customError("msg1"),
		},
	} {
		assert.Equal(t, test.rootCause, stacktrace.RootCause(test.err))
	}
}
Exemplo n.º 2
0
func TestGetCode(t *testing.T) {
	for _, test := range []struct {
		originalError error
		originalCode  stacktrace.ErrorCode
	}{
		{
			originalError: errors.New("err"),
			originalCode:  stacktrace.NoCode,
		},
		{
			originalError: stacktrace.NewError("err"),
			originalCode:  stacktrace.NoCode,
		},
		{
			originalError: stacktrace.NewErrorWithCode(EcodeInvalidVillain, "err"),
			originalCode:  EcodeInvalidVillain,
		},
		{
			originalError: stacktrace.NewMessageWithCode(EcodeNoSuchPseudo, "err"),
			originalCode:  EcodeNoSuchPseudo,
		},
	} {
		err := test.originalError
		assert.Equal(t, test.originalCode, stacktrace.GetCode(err))

		err = stacktrace.Propagate(err, "")
		assert.Equal(t, test.originalCode, stacktrace.GetCode(err))

		err = stacktrace.PropagateWithCode(err, EcodeNotFastEnough, "")
		assert.Equal(t, EcodeNotFastEnough, stacktrace.GetCode(err))

		err = stacktrace.PropagateWithCode(err, EcodeTimeIsIllusion, "")
		assert.Equal(t, EcodeTimeIsIllusion, stacktrace.GetCode(err))
	}
}
Exemplo n.º 3
0
func startDoing() error {
	return stacktrace.NewError("%s %s %s %s", "failed", "to", "start", "doing")
}