// NewPanicCheck creates a handler responsible for checking for panics and setting the Healthcheck to fail.
169191
func NewPanicCheck(healthcheck *threading.SharedBoolean, logger logger.Logger) negroni.Handler {
	return &panicCheck{
		heartbeatOK: healthcheck,
		logger:      logger,
	}
}
618022
func defaultPanicHandler() {
	defer defaultNotifier.dontPanic()
	ctx := sessions.SendStartupSession(&sessionTrackingConfig)

	err := panicwrap.BasicMonitor(func(output string) {
		toNotify, err := errors.ParsePanic(output)

		if err != nil {
			defaultNotifier.Config.logf("bugsnag.handleUncaughtPanic: %v", err)
		}
		state := HandledState{SeverityReasonUnhandledPanic, SeverityError, true, ""}
		defaultNotifier.NotifySync(toNotify, true, state, ctx)

	})

	if err != nil {
		defaultNotifier.Config.logf("bugsnag.handleUncaughtPanic: %v", err)
	}
}
1166953
func outputPanic(ctx context.Context, recovered interface{}) {
	msg := fmt.Sprintf("Recovered panic: %s.", recovered)
	log.LoggerWContext(ctx).Error(msg)
	fmt.Fprintln(os.Stderr, msg)
	debug.PrintStack()
}
494452
func NewMockPitayaServer(ctrl *gomock.Controller) *MockPitayaServer {
	mock := &MockPitayaServer{ctrl: ctrl}
	mock.recorder = &MockPitayaServerMockRecorder{mock}
	return mock
}
257717
func WithPanicCatcher(c *router.Context, next router.Handler) {
	ctx := c.Context
	w := c.Writer
	req := c.Request
	defer paniccatcher.Catch(func(p *paniccatcher.Panic) {
		// Log the reason before the stack in case appengine cuts entire log
		// message due to size limitations.
		log.Fields{
			"panic.error": p.Reason,
		}.Errorf(ctx, "Caught panic during handling of %q: %s\n%s", req.RequestURI, p.Reason, p.Stack)

		// Note: it may be too late to send HTTP 500 if `next` already sent
		// headers. But there's nothing else we can do at this point anyway.
		http.Error(w, "Internal Server Error. See logs.", http.StatusInternalServerError)
	})
	next(c)
}
879492
func ourPanic() bool {
	if !canDetect {
		return false
	}

	framebuf := make([]uintptr, maxPanicDepth)
	copied := runtime.Callers(0, framebuf)
	framebuf = framebuf[:copied]
	for _, pc := range framebuf {
		if frameForPC(pc).Function == "github.com/bobziuchkovski/cue.doPanic" {
			return true
		}
	}
	return false
}
788767
func GoPanic(r interface{}, stack []byte, cont bool) {
	log.di(fnLevelDiPlus1).GoPanic(r, stack, cont)
}
571524
func (plugin *ExamplePlugin) showPanicLog() {
	defer func() {
		if err := recover(); err != nil {
			plugin.Log.Info("Recovered from panic")
		}
	}()
	plugin.Log.Panic("Panic log: calls panic() after log, will be recovered") //calls panic() after logging
}
1154256
func (l *State) AddCheck(check *structs.HealthCheck, token string) error {
	l.Lock()
	defer l.Unlock()

	return l.addCheckLocked(check, token)
}
429025
func trackPanic(r io.Reader, w io.Writer, dur time.Duration, result chan<- string) {
	defer close(result)

	var panicTimer <-chan time.Time
	panicBuf := new(bytes.Buffer)
	panicHeaders := [][]byte{
		[]byte("panic:"),
		[]byte("fatal error: fault"),
	}
	panicType := -1

	tempBuf := make([]byte, 2048)
	for {
		var buf []byte
		var n int

		if panicTimer == nil && panicBuf.Len() > 0 {
			// We're not tracking a panic but the buffer length is
			// greater than 0. We need to clear out that buffer, but
			// look for another panic along the way.

			// First, remove the previous panic header so we don't loop
			w.Write(panicBuf.Next(len(panicHeaders[panicType])))

			// Next, assume that this is our new buffer to inspect
			n = panicBuf.Len()
			buf = make([]byte, n)
			copy(buf, panicBuf.Bytes())
			panicBuf.Reset()
		} else {
			var err error
			buf = tempBuf
			n, err = r.Read(buf)
			if n <= 0 && err == io.EOF {
				if panicBuf.Len() > 0 {
					// We were tracking a panic, assume it was a panic
					// and return that as the result.
					result <- panicBuf.String()
				}

				return
			}
		}

		if panicTimer != nil {
			// We're tracking what we think is a panic right now.
			// If the timer ended, then it is not a panic.
			isPanic := true
			select {
			case <-panicTimer:
				isPanic = false
			default:
			}

			// No matter what, buffer the text some more.
			panicBuf.Write(buf[0:n])

			if !isPanic {
				// It isn't a panic, stop tracking. Clean-up will happen
				// on the next iteration.
				panicTimer = nil
			}

			continue
		}

		panicType = -1
		flushIdx := n
		for i, header := range panicHeaders {
			idx := bytes.Index(buf[0:n], header)
			if idx >= 0 {
				panicType = i
				flushIdx = idx
				break
			}
		}

		// Flush to stderr what isn't a panic
		w.Write(buf[0:flushIdx])

		if panicType == -1 {
			// Not a panic so just continue along
			continue
		}

		// We have a panic header. Write we assume is a panic os far.
		panicBuf.Write(buf[flushIdx:n])
		panicTimer = time.After(dur)
	}
}
1251897
func (tsv *TabletServer) HandlePanic(err *error) {
	if x := recover(); x != nil {
		*err = fmt.Errorf("uncaught panic: %v\n. Stack-trace:\n%s", x, tb.Stack(4))
	}
}
406963
func NewCheck() *Check {
	ch := &Check{}
	ch.manualOverride.Store(false)
	ch.manualHealthState.Store(false)
	return ch
}
1044025
func ParsePanic(text string) (*Error, error) {
	lines := strings.Split(text, "\n")

	state := "start"

	var message string
	var stack []StackFrame

	for i := 0; i < len(lines); i++ {
		line := lines[i]

		if state == "start" {
			if strings.HasPrefix(line, "panic: ") {
				message = strings.TrimPrefix(line, "panic: ")
				state = "seek"
			} else {
				return nil, Errorf("bugsnag.panicParser: Invalid line (no prefix): %s", line)
			}

		} else if state == "seek" {
			if strings.HasPrefix(line, "goroutine ") && strings.HasSuffix(line, "[running]:") {
				state = "parsing"
			}

		} else if state == "parsing" {
			if line == "" {
				state = "done"
				break
			}
			createdBy := false
			if strings.HasPrefix(line, "created by ") {
				line = strings.TrimPrefix(line, "created by ")
				createdBy = true
			}

			i++

			if i >= len(lines) {
				return nil, Errorf("bugsnag.panicParser: Invalid line (unpaired): %s", line)
			}

			frame, err := parsePanicFrame(line, lines[i], createdBy)
			if err != nil {
				return nil, err
			}

			stack = append(stack, *frame)
			if createdBy {
				state = "done"
				break
			}
		}
	}

	if state == "done" || state == "parsing" {
		return &Error{Err: uncaughtPanic{message}, frames: stack}, nil
	}
	return nil, Errorf("could not parse panic: %v", text)
}
250141
func NewMocks3Handler(ctrl *gomock.Controller) *Mocks3Handler {
	mock := &Mocks3Handler{ctrl: ctrl}
	mock.recorder = &Mocks3HandlerMockRecorder{mock}
	return mock
}
103853
func UnmarshalConfigOrPanic(data []byte) *cb.Config {
	result, err := UnmarshalConfig(data)
	if err != nil {
		panic(err)
	}
	return result
}
1045730
func didPanic(f PanicTestFunc) (bool, interface{}) {

	didPanic := false
	var message interface{}
	func() {

		defer func() {
			if message = recover(); message != nil {
				didPanic = true
			}
		}()

		// call the target function
		f()

	}()

	return didPanic, message

}
1245215
func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {
	if h, ok := a.t.(tHelper); ok {
		h.Helper()
	}
	NotPanics(a.t, f, msgAndArgs...)
}