// NewErrorClass creates a new error class.
// It is the responsibility of the client to guarantee uniqueness of code.
353744
func NewErrorClass(code string, status int) ErrorClass {
	return func(message interface{}, keyvals ...interface{}) error {
		var msg string
		switch actual := message.(type) {
		case string:
			msg = actual
		case error:
			msg = actual.Error()
		case fmt.Stringer:
			msg = actual.String()
		default:
			msg = fmt.Sprintf("%v", actual)
		}
		var meta map[string]interface{}
		l := len(keyvals)
		if l > 0 {
			meta = make(map[string]interface{})
		}
		for i := 0; i < l; i += 2 {
			k := keyvals[i]
			var v interface{} = "MISSING"
			if i+1 < l {
				v = keyvals[i+1]
			}
			meta[fmt.Sprintf("%v", k)] = v
		}
		return &ErrorResponse{ID: newErrorID(), Code: code, Status: status, Detail: msg, Meta: meta}
	}
}
944368
func NewError(statuscode int, msg string) *Error {
	return &Error{StatusCode: statuscode, Message: msg}
}
367488
func newError(StatusCode int, Text string) *Error {
	return &Error{
		StatusCode: StatusCode,
		Text:       Text,
	}
}
1333275
func NewONSError(e error, description string) *ONSError {
	err := &ONSError{RootError: e}
	err.AddParameter("ErrorDescription", description)
	return err
}
1042004
func NewErrorV1(code, f string, a ...interface{}) *ErrorV1 {
	return &ErrorV1{
		Code:    code,
		Message: fmt.Sprintf(f, a...),
	}
}
148501
func newError(status uint16) error {
	switch status {
	case StatusOK:
		return nil
	case StatusNotFound:
		return ErrNotFound
	case StatusKeyExists:
		return ErrKeyExists
	case StatusValueTooLarge:
		return ErrValueTooLarge
	case StatusInvalidArgs:
		return ErrInvalidArgs
	case StatusValueNotStored:
		return ErrValueNotStored
	case StatusNonNumeric:
		return ErrNonNumeric
	case StatusAuthRequired:
		return ErrAuthRequired

	// we only support PLAIN auth, no mechanism that would make use of auth
	// continue, so make it an error for now for completeness.
	case StatusAuthContinue:
		return ErrAuthContinue
	case StatusUnknownCommand:
		return ErrUnknownCommand
	case StatusOutOfMemory:
		return ErrOutOfMemory
	}
	return ErrUnknownError
}
1349294
func NewErrors() *Errors {
	return &Errors{
		Errors: make(map[string][]string),
		Lock:   new(sync.RWMutex),
	}
}
482765
func NewErrorEvent(ts int64, path string, record interface{}, message string) Event {
	e := &errorEvent{
		Ts:      ts,
		Kind:    "error",
		Path:    path,
		Record:  record,
		Message: message,
	}
	return e
}
1269750
func NewEmmErrorType(Description string) *EmmErrorType {
	s := new(EmmErrorType)
	s.Description = Description
	return s
}
726071
func NewClass(id, fingerprint string, sample bool) *Class {
	class := &Class{
		Id:           id,
		Fingerprint:  fingerprint,
		Metrics:      NewMetrics(),
		TotalQueries: 0,
		Example:      &Example{},
		sample:       sample,
	}
	return class
}
126820
func NewError(code int, msg ...string) *Error {
	e := &errors.CodedError{
		Code: int32(code),
	}
	switch len(msg) {
	case 0:
		e.Message = http.StatusText(code)
	case 1:
		e.Message = msg[0]
	case 2:
		e.Message = msg[0]
		e.Detail = msg[1]
	}
	return (*Error)(e)
}
278050
func NewApiError(code int, msg string) *Error {
	return &Error{
		apiError: &apiError{
			code: code,
			msg:  msg,
		},
		Err: nil,
	}
}
1128013
func (e *ErrorClass) NewWith(message string, options ...ErrorOption) error {
	return e.wrap(errors.New(message), nil, options)
}
72188
func NewCliError(reqType string, hr *gocd.APIResponse, err error) (jerr JSONCliError) {
	data := dataJSONCliError{
		"error": err.Error(),
	}
	if hr != nil {
		data["status"] = hr.HTTP.StatusCode
		data["response-body"] = hr.Body
		data["request-endpoint"] = hr.Request.HTTP.URL.String()

		if hr.HTTP.StatusCode == 404 {
			data["error"] = "Resource not found"
		} else {
			b1, _ := json.Marshal(hr.HTTP.Header)
			b2, _ := json.Marshal(hr.Request.HTTP.Header)
			data["error"] = "An error occurred while retrieving the resource."
			data["response-header"] = string(b1)
			data["request-body"] = hr.Request.Body
			data["request-header"] = string(b2)
		}
	} else {
		data["request"] = reqType
	}
	return JSONCliError{
		data: data,
		resp: hr,
	}
}
252502
func NewAPIError(opName string, payload interface{}, code int) *APIError {
	return &APIError{
		OperationName: opName,
		Response:      payload,
		Code:          code,
	}
}
150681
func newErrorf(StatusCode int, Text string, Parameters ...interface{}) *Error {
	return newError(StatusCode, fmt.Sprintf(Text, Parameters...))
}
1117160
func NewErrorFromPanic(err interface{}) *Error {

	// Parse the filename and line from the originating line of app code.
	// /Users/robfig/code/gocode/src/revel/examples/booking/app/controllers/hotels.go:191 (0x44735)
	stack := string(debug.Stack())
	frame, basePath := findRelevantStackFrame(stack)
	if frame == -1 {
		return nil
	}

	stack = stack[frame:]
	stackElement := stack[:strings.Index(stack, "\n")]
	colonIndex := strings.LastIndex(stackElement, ":")
	filename := stackElement[:colonIndex]
	var line int
	fmt.Sscan(stackElement[colonIndex+1:], &line)

	// Show an error page.
	description := "Unspecified error"
	if err != nil {
		description = fmt.Sprint(err)
	}
	lines, readErr := ReadLines(filename)
	if readErr != nil {
		utilLog.Error("Unable to read file", "file", filename, "error", readErr)
	}
	return &Error{
		Title:       "Runtime Panic",
		Path:        filename[len(basePath):],
		Line:        line,
		Description: description,
		SourceLines: lines,
		Stack:       stack,
	}
}