// CapturePanic calls f and then recovers and reports a panic to the Sentry server if it occurs.
// If an error is captured, both the error and the reported Sentry error ID are returned.
545976
func (client *Client) CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string) {
	// Note: This doesn't need to check for client, because we still want to go through the defer/recover path
	// Down the line, Capture will be noop'd, so while this does a _tiny_ bit of overhead constructing the
	// *Packet just to be thrown away, this should not be the normal case. Could be refactored to
	// be completely noop though if we cared.
	defer func() {
		var packet *Packet
		err = recover()
		switch rval := err.(type) {
		case nil:
			return
		case error:
			if client.shouldExcludeErr(rval.Error()) {
				return
			}
			packet = NewPacket(rval.Error(), append(append(interfaces, client.context.interfaces()...), NewException(rval, NewStacktrace(2, 3, client.includePaths)))...)
		default:
			rvalStr := fmt.Sprint(rval)
			if client.shouldExcludeErr(rvalStr) {
				return
			}
			packet = NewPacket(rvalStr, append(append(interfaces, client.context.interfaces()...), NewException(errors.New(rvalStr), NewStacktrace(2, 3, client.includePaths)))...)
		}

		errorID, _ = client.Capture(packet, tags)
	}()

	f()
	return
}
1048159
func (l *DefaultLogger) LogPanic(_ context.Context, value interface{}) {
	const size = 64 << 10
	buf := make([]byte, size)
	buf = buf[:runtime.Stack(buf, false)]
	log.Printf("graphql: panic occurred: %v\n%s", value, buf)
}
12324
func (qi *QuotedIdentifier) Capture(values []string) error {
	// Remove enclosing quotes
	n := len(values[0])
	r := values[0][1 : n-1]

	// Translate doubled quotes
	*qi = QuotedIdentifier(strings.Replace(r, `""`, `"`, -1))
	return nil
}
1150412
func LogPanicWithStack(log Interface, location string, r interface{}, vals ...interface{}) error {
	if log == nil {
		log = internal
	}
	var err error
	switch t := r.(type) {
	case string:
		err = errors.New(t)
	case error:
		err = t
	default:
		err = errors.Errorf("unkown type(%T) error: %v", r, r)
	}
	os.Mkdir("panics", os.ModePerm)
	b, tmpErr := ioutil.TempFile("panics", location)
	if tmpErr != nil {
		log.Log("event", "panic", "location", location, "err", err, "warning", "no temp file", "tmperr", tmpErr)
		return errors.Wrapf(tmpErr, "LogPanic: failed to create httpRecovery log")
	}

	fmt.Fprintf(b, "warning! %s!\nError:\n%+v\n", location, err)
	for i, v := range vals {
		spew.Fdump(b, "val(%d): %#v\n", i, v)
	}
	fmt.Fprintf(b, "\n\nCall Stack:\n%s", debug.Stack())

	log.Log("event", "panic", "location", location, "panicLog", b.Name())
	fmt.Fprintf(os.Stderr, "panicWithStack: wrote %s\n", b.Name())

	return errors.Wrap(b.Close(), "LogPanic: failed to close dump file")
}
319760
func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string) {
	return DefaultClient.CapturePanicAndWait(f, tags, interfaces...)
}
1050548
func PanicContextHandler(fx FlatHandler, p func(*Context, interface{})) FlatHandler {
	return func(c *Context, next NextHandler) {
		defer func() {
			if err := recover(); err != nil {
				p(c, err)
			}
		}()

		fx(c, next)
	}
}
75168
func DefaultPanicHandler(ctx *Context, panicReason interface{}) {
	ctx.SetStatusCode(500)
	if strings.HasPrefix(string(ctx.Request.Header.Peek("Accept")), "text/html") || strings.Contains(ctx.ContentType(), "text/html") {
		_, err := ctx.HTML().WriteString(handledPanic)
		if err != nil {
			ctx.Logger.WithError(err).Error("could not serve default panic page")
			return
		}
		if !ctx.App.PanicHandlerNoPoweredBy {
			if _, err := ctx.WriteString(poweredBy); err != nil {
				// connection broken
				ctx.Error("", 500)
			}
		}
		if len(ctx.App.PanicHandlerCustomLayout) > 0 {
			if _, err := ctx.WriteString(ctx.App.PanicHandlerCustomLayout); err != nil {
				// connection broken
				ctx.Error("", 500)
			}
		}
		return
	}

	if _, err := ctx.Encode(errGotPanic); err != nil {
		ctx.Error("", 500)
	}
}
688357
func ExtractPayloadOrPanic(envelope *cb.Envelope) *cb.Payload {
	payload, err := ExtractPayload(envelope)
	if err != nil {
		panic(err)
	}
	return payload
}
1060026
func (r *Hook) ReportPanic() {
	if p := recover(); p != nil {
		if _, err := r.Client.Critical(fmt.Errorf("panic: %q", p), nil); err != nil {
			fmt.Fprintf(os.Stderr, "reporting_panic=false err=%q\n", err)
		}
		panic(p)
	}
}
24902
func HandlePanic(fn func()) func() {
	return func() {
		defer func() {
			if r := recover(); r != nil {
				for _, fn := range utilruntime.PanicHandlers {
					fn(r)
				}
				panic(r)
			}
		}()
		// call the function
		fn()
	}
}
1356404
func (agent *ActionAgent) HandleRPCPanic(ctx context.Context, name string, args, reply interface{}, verbose bool, err *error) {
	// panic handling
	if x := recover(); x != nil {
		log.Errorf("TabletManager.%v(%v) on %v panic: %v\n%s", name, args, topoproto.TabletAliasString(agent.TabletAlias), x, tb.Stack(4))
		*err = fmt.Errorf("caught panic during %v: %v", name, x)
		return
	}

	// quick check for fast path
	if !verbose && *err == nil {
		return
	}

	// we gotta log something, get the source
	from := ""
	ci, ok := callinfo.FromContext(ctx)
	if ok {
		from = ci.Text()
	}

	if *err != nil {
		// error case
		log.Warningf("TabletManager.%v(%v)(on %v from %v) error: %v", name, args, topoproto.TabletAliasString(agent.TabletAlias), from, (*err).Error())
		*err = vterrors.Wrapf(*err, "TabletManager.%v on %v error: %v", name, topoproto.TabletAliasString(agent.TabletAlias), (*err).Error())
	} else {
		// success case
		log.Infof("TabletManager.%v(%v)(on %v from %v): %#v", name, args, topoproto.TabletAliasString(agent.TabletAlias), from, reply)
	}
}
75357
func HandlePanic() {
	stackTraceBytes := make([]byte, maxStackSizeLimit)
	runtime.Stack(stackTraceBytes, true)
	stackTrace := "\t" + strings.Replace(string(stackTraceBytes), "\n", "\n\t", -1)
	if err := recover(); err != nil {
		formattedString := `
		Something unexpected happened. This is a bug in {{.Binary}}.

		Please re-run the command that caused this exception with the environment
		variable CF_TRACE set to true.

		Also, please update to the latest cli and try the command again:
		https://code.cloudfoundry.org/cli/releases

		Please create an issue at: https://code.cloudfoundry.org/cli/issues

		Include the below information when creating the issue:

		Command
		{{.Command}}

		CLI Version
		{{.Version}}

		Error
		{{.Error}}

		Stack Trace
		{{.StackTrace}}

		Your Platform Details
		e.g. Mac OS X 10.11, Windows 8.1 64-bit, Ubuntu 14.04.3 64-bit

		Shell
		e.g. Terminal, iTerm, Powershell, Cygwin, gnome-terminal, terminator
		`
		formattedTemplate := template.Must(template.New("Panic Template").Parse(formattedString))
		templateErr := formattedTemplate.Execute(os.Stderr, map[string]interface{}{
			"Binary":     os.Args[0],
			"Command":    strings.Join(os.Args, " "),
			"Version":    version.VersionString(),
			"StackTrace": stackTrace,
			"Error":      err,
		})
		if templateErr != nil {
			fmt.Fprintf(os.Stderr,
				"Unable to format panic response: %s\n",
				templateErr.Error(),
			)

			fmt.Fprintf(os.Stderr,
				"Version:%s\nCommand:%s\nOriginal Stack Trace:%s\nOriginal Error:%s\n",
				version.VersionString(),
				strings.Join(os.Args, " "),
				stackTrace,
				err,
			)
		}
		os.Exit(1)
	}
}
277012
func LogPanic() {
	if rec := recover(); rec != nil {
		switch e := rec.(type) {
		case error:
			WithError(e).Panic(e.Error())
		default:
			Panicf("%v", rec)
		}
	}
}
200409
func UnmarshalConfigEnvelopeOrPanic(data []byte) *cb.ConfigEnvelope {
	result, err := UnmarshalConfigEnvelope(data)
	if err != nil {
		panic(err)
	}
	return result
}
1268897
func PanicHandlerFunc(h http.HandlerFunc, errH http.HandlerFunc) http.HandlerFunc {
	return PanicHandler(h, errH)
}
1177442
func logPanic(r interface{}) {
	callers := ""
	for i := 0; true; i++ {
		_, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}
		callers = callers + fmt.Sprintf("%v:%v\n", file, line)
	}
	glog.Errorf("Recovered from panic: %#v (%v)\n%v", r, r, callers)
}
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)
	}
}