// NewRFCErrorOrPanic creates an rfc2119.Error referencing a spec
// violation and panics on failure.  This is handy for situations
// where you can't be bothered to check NewRFCError for failure.
15940
func NewRFCErrorOrPanic(code Code, err error, version string) *rfc2119.Error {
	rfcError, err2 := NewRFCError(code, err, version)
	if err2 != nil {
		panic(err2.Error())
	}
	return rfcError
}
37056
func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rc int) {
	state := request.Request{W: w, Req: r}

	answer := new(dns.Msg)
	answer.SetRcode(r, rc)

	state.SizeAndDo(answer)

	vars.Report(state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())

	w.WriteMsg(answer)
}
243262
func NewOnionErrorEncrypter(router *Router,
	ephemeralKey *btcec.PublicKey) (*OnionErrorEncrypter, error) {

	sharedSecret, err := router.generateSharedSecret(ephemeralKey)
	if err != nil {
		return nil, err
	}

	return &OnionErrorEncrypter{
		sharedSecret: sharedSecret,
	}, nil
}
1009267
func newErrNoDescriber(types ...reflect.Type) error {
	names := make([]string, 0, len(types))
	for _, t := range types {
		names = append(names, t.String())
	}
	return describe.ErrNoDescriber{Types: names}
}
159716
func NewErrorFrom(kind ErrorKind, inner error) *Error {
	return &Error{
		kind:  kind,
		inner: inner,
	}
}
904213
func NewClientErr(parent error, code string, description string) *ClientErr {
	return &ClientErr{parent, code, description}
}
294597
func NewFailOnError(authTokenHandlers ...authenticator.Token) authenticator.Token {
	if len(authTokenHandlers) == 1 {
		return authTokenHandlers[0]
	}
	return &unionAuthTokenHandler{Handlers: authTokenHandlers, FailOnError: true}
}
106587
func NewErrorResponder(err error) Responder {
	return func(req *http.Request) (*http.Response, error) {
		return nil, err
	}
}
771753
func NewRPCResponseWriter() *RPCResponseWriter {
	w := &RPCResponseWriter{
		header:     make(http.Header),
		body:       new(bytes.Buffer),
		statusCode: 200,
	}
	//w.header.Set("Content-Type", "application/octet-stream")
	return w
}
844368
func NewDefaultRocRWithSrcLen(sourceLength uint) (indicator *RocR, err error) {
	ind, err := NewDefaultRocR()

	// only initialise the storage if there is enough source data to require it
	if sourceLength-uint(ind.GetLookbackPeriod()) > 1 {
		ind.Data = make([]float64, 0, sourceLength-uint(ind.GetLookbackPeriod()))
	}

	return ind, err
}
1031653
func GetPanicError(w http.ResponseWriter) (interface{}, bool) {
	er, ok := GetResponseWriter(w, func(tst http.ResponseWriter) bool {
		_, ok := tst.(*errResponseWriter)
		return ok
	})
	if ok {
		return er.(*errResponseWriter).perr, true
	}
	return nil, false
}
271574
func NewEnforcerSafe(params ...interface{}) (e *Enforcer, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("%v", r)
			e = nil
		}
	}()

	e = NewEnforcer(params...)
	err = nil
	return
}
812445
func NewDefaultRocR100ForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber) (indicator *RocR100, err error) {
	ind, err := NewDefaultRocR100WithSrcLen(sourceLength)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
842421
func NewJiraError(resp *Response, httpError error) error {
	if resp == nil {
		return errors.Wrap(httpError, "No response returned")
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return errors.Wrap(err, httpError.Error())
	}
	jerr := Error{HTTPError: httpError}
	contentType := resp.Header.Get("Content-Type")
	if strings.HasPrefix(contentType, "application/json") {
		err = json.Unmarshal(body, &jerr)
		if err != nil {
			httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error())
			return errors.Wrap(err, httpError.Error())
		}
	} else {
        if httpError == nil {
            return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body))
        }
		return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body)))
	}

	return &jerr
}
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))
	}
}
417883
func handleInvocationPanic(c *Controller, err interface{}) {
	error := NewErrorFromPanic(err)
	if error != nil {
		utilLog.Error("PanicFilter: Caught panic", "error", err, "stack", error.Stack)
		if DevMode {
			fmt.Println(err)
			fmt.Println(error.Stack)
		}
	} else {
		utilLog.Error("PanicFilter: Caught panic, unable to determine stack location", "error", err, "stack", string(debug.Stack()))
		if DevMode {
			fmt.Println(err)
			fmt.Println("stack", string(debug.Stack()))
		}
	}

	if error == nil && DevMode {
		// Only show the sensitive information in the debug stack trace in development mode, not production
		c.Response.SetStatus(http.StatusInternalServerError)
		_, _ = c.Response.GetWriter().Write(debug.Stack())
		return
	}

	c.Result = c.RenderError(error)
}
300950
func SetOrPanic(s Setter) func(v string) {
	return func(v string) {
		err := s.Set(v)
		if err != nil {
			panic(err)
		}
	}
}