示例#1
0
文件: main.go 项目: yingkitw/cli
func handlePanics(printer terminal.Printer, logger trace.Printer) {
	panicprinter.UI = terminal.NewUI(os.Stdin, Writer, printer, logger)

	commandArgs := strings.Join(os.Args, " ")
	stackTrace := generateBacktrace()

	err := recover()
	panicprinter.DisplayCrashDialog(err, commandArgs, stackTrace)

	if err != nil {
		os.Exit(1)
	}
}
示例#2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Panic Printer", func() {
	var ui *testterm.FakeUI

	BeforeEach(func() {
		panicprinter.UI = &testterm.FakeUI{}
		ui = panicprinter.UI.(*testterm.FakeUI)
	})

	Describe("DisplayCrashDialog", func() {
		It("includes the error message when given an error", func() {
			panicprinter.DisplayCrashDialog(errors.New("some-error"), "some command", "some trace")
			Expect(len(ui.Outputs)).To(BeNumerically(">", 0))
			Expect(ui.Outputs).To(ContainElement(ContainSubstring("some-error")))
		})

		It("includes the string when given a string that is not terminal.QuietPanic", func() {
			panicprinter.DisplayCrashDialog("some-error", "some command", "some trace")
			Expect(len(ui.Outputs)).To(BeNumerically(">", 0))
			Expect(ui.Outputs).To(ContainElement(ContainSubstring("some-error")))
		})

		It("does not print anything when given a string that is terminal.QuietPanic", func() {
			err := terminal.QuietPanic
			panicprinter.DisplayCrashDialog(err, "some command", "some trace")
			Expect(len(ui.Outputs)).To(Equal(0))
		})