// NewRandOrPanic return a new amcl PRG or panic
519507
func NewRandOrPanic() *amcl.RAND {
	rng, err := cryptolib.GetRand()
	if err != nil {
		panic(err)
	}
	return rng
}
1070971
func NewGuaranteedThroughputProbabilisticSampler(
	lowerBound, samplingRate float64,
) (*GuaranteedThroughputProbabilisticSampler, error) {
	return newGuaranteedThroughputProbabilisticSampler(lowerBound, samplingRate), nil
}
636038
func checkResourcesOrPanic(res channelconfig.Resources) {
	if err := checkResources(res); err != nil {
		logger.Panicf("[channel %s] %s", res.ConfigtxValidator().ChainID(), err)
	}
}
995339
func NewRandomBalancer(targets []*ProxyTarget) ProxyBalancer {
	b := &randomBalancer{commonBalancer: new(commonBalancer)}
	b.targets = targets
	return b
}
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

}
946662
func HandlePanic(component string, err *error) {
	if x := recover(); x != nil {
		// gRPC 0.13 chokes when you return a streaming error that contains newlines.
		*err = fmt.Errorf("uncaught %v panic: %v, %s", component, x,
			strings.Replace(string(tb.Stack(4)), "\n", ";", -1))
	}
}
947968
func SignOrPanic(signer crypto.LocalSigner, msg []byte) []byte {
	if signer == nil {
		panic(errors.New("invalid signer. cannot be nil"))
	}

	sigma, err := signer.Sign(msg)
	if err != nil {
		panic(fmt.Errorf("failed generating signature: %s", err))
	}
	return sigma
}
897080
func (vtg *VTGate) HandlePanic(err *error) {
	if x := recover(); x != nil {
		log.Errorf("Uncaught panic:\n%v\n%s", x, tb.Stack(4))
		*err = fmt.Errorf("uncaught panic: %v, vtgate: %v", x, servenv.ListeningURL.String())
		errorCounts.Add([]string{"Panic", "Unknown", "Unknown", vtrpcpb.Code_INTERNAL.String()}, 1)
	}
}
1193970
func NewLogAggregatorDecorator(
	kinesisResource *gocf.KinesisStream,
	kinesisMapping *sparta.EventSourceMapping,
	relay *sparta.LambdaAWSInfo) *LogAggregatorDecorator {

	return &LogAggregatorDecorator{
		kinesisStreamResourceName: logAggregatorResName("Kinesis"),
		kinesisResource:           kinesisResource,
		kinesisMapping:            kinesisMapping,
		iamRoleNameResourceName:   logAggregatorResName("IAMRole"),
		logRelay:                  relay,
	}
}
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)
	}
}
882727
func (cm ConfigMap) FindOrPanic(am AuthMechanism) interface{} {
	obj, ok := cm[am]
	if !ok {
		panic(ErrMissingConfiguration)
	}
	return obj
}
506660
func MarshalOrPanic(pb proto.Message) []byte {
	data, err := proto.Marshal(pb)
	if err != nil {
		panic(err)
	}
	return data
}
688357
func ExtractPayloadOrPanic(envelope *cb.Envelope) *cb.Payload {
	payload, err := ExtractPayload(envelope)
	if err != nil {
		panic(err)
	}
	return payload
}
1360288
func NewRandTicker(d, variance time.Duration) *RandTicker {
	c := make(chan time.Time, 1)
	done := make(chan struct{})
	go func() {
		rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
		for {
			vr := time.Duration(rnd.Int63n(int64(2*variance)) - int64(variance))
			tmr := time.NewTimer(d + vr)
			select {
			case <-tmr.C:
				select {
				case c <- time.Now():
				default:
				}
			case <-done:
				tmr.Stop()
				close(c)
				return
			}
		}
	}()
	return &RandTicker{
		C:    c,
		done: done,
	}
}
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)
	}
}
909871
func NewRandomPartitioner(topic string) Partitioner {
	p := new(randomPartitioner)
	p.generator = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
	return p
}
300950
func SetOrPanic(s Setter) func(v string) {
	return func(v string) {
		err := s.Set(v)
		if err != nil {
			panic(err)
		}
	}
}