Beispiel #1
0
func handleError(v interface{}) {
	if err, ok := v.(exitError); ok {
		life.Exit(int(err))
		return
	}

	cause := errors.GetPanicCausedBy(v)
	if cause == errors.NoError {
		return
	}

	errors.Handle(nil, v)

	switch cause {
	case errors.ByBug, errors.ByRuntime:
		fmt.Fprintln(os.Stderr, v)
		buf := make([]byte, 16*1024)
		buf = buf[0:runtime.Stack(buf, true)]
		fmt.Fprintln(os.Stderr, string(buf))
	case errors.ByInput, errors.ByExternal:
		fmt.Println(v)
	default:
		panic("Unknown CausedBy")
	}
	life.Exit(int(cause) + 1)
}
Beispiel #2
0
	AfterEach(func() {
		reset.Disable()
	})

	It("Context not nil", func() {
		called := 0
		ctx := context.WithValue(context.Background(), "foo", 1)

		errors.SetHandler(func(actx context.Context, err interface{}) {
			called++
			Ω(err).Should(Equal(3))
			Ω(actx).Should(Equal(ctx))
		})

		errors.Handle(ctx, 3)
		Ω(called).Should(Equal(1))
	})

	It("Context is nil", func() {
		called := 0
		errors.SetHandler(func(ctx context.Context, err interface{}) {
			called++
			Ω(ctx).Should(Equal(context.Background()))
		})

		errors.Handle(nil, 2)
		Ω(called).Should(Equal(1))
	})

})