// FromError returns the Status for the provided error. If the provided error
// is not a Status, a new error with code CodeUnknown is returned.
//
// Returns nil if the provided error is nil.
161526
func FromError(err error) *Status {
	if err == nil {
		return nil
	}
	if status, ok := err.(*Status); ok {
		return status
	}
	return &Status{
		code:    CodeUnknown,
		message: err.Error(),
	}
}
1286495
func FromStatus(s *status.Status) *platform.Error {
	if s == nil || s.Code() == codes.OK {
		return nil
	}

	msg := s.Message()
	var perr platform.Error
	if err := json.Unmarshal([]byte(msg), &perr); err != nil {
		return &platform.Error{
			Err:  errors.New(msg),
			Code: platform.EInternal,
		}
	}

	return &perr
}
268507
func (defaultErrorHandler) HandleError(err error, w http.ResponseWriter, req *http.Request) {
	w.WriteHeader(http.StatusInternalServerError)
	fmt.Fprintf(w, "Error: %s", err)
}
1244552
func RestoreError(err error) error {
	err = errors.Cause(err)

	if apiErr, ok := err.(*params.Error); !ok {
		return err
	} else if apiErr == nil {
		return nil
	}
	if params.ErrCode(err) == "" {
		return err
	}
	msg := err.Error()

	if singleton, ok := singletonError(err); ok {
		return singleton
	}

	// TODO(ericsnow) Support the other error types handled by ServerError().
	switch {
	case params.IsCodeUnauthorized(err):
		return errors.NewUnauthorized(nil, msg)
	case params.IsCodeNotFound(err):
		// TODO(ericsnow) UnknownModelError should be handled here too.
		// ...by parsing msg?
		return errors.NewNotFound(nil, msg)
	case params.IsCodeUserNotFound(err):
		return errors.NewUserNotFound(nil, msg)
	case params.IsCodeAlreadyExists(err):
		return errors.NewAlreadyExists(nil, msg)
	case params.IsCodeNotAssigned(err):
		return errors.NewNotAssigned(nil, msg)
	case params.IsCodeHasAssignedUnits(err):
		// TODO(ericsnow) Handle state.HasAssignedUnitsError here.
		// ...by parsing msg?
		return err
	case params.IsCodeHasHostedModels(err):
		return err
	case params.IsCodeHasPersistentStorage(err):
		return err
	case params.IsCodeModelNotEmpty(err):
		return err
	case params.IsCodeNoAddressSet(err):
		// TODO(ericsnow) Handle isNoAddressSetError here.
		// ...by parsing msg?
		return err
	case params.IsCodeNotProvisioned(err):
		return errors.NewNotProvisioned(nil, msg)
	case params.IsCodeUpgradeInProgress(err):
		// TODO(ericsnow) Handle state.UpgradeInProgressError here.
		// ...by parsing msg?
		return err
	case params.IsCodeMachineHasAttachedStorage(err):
		// TODO(ericsnow) Handle state.HasAttachmentsError here.
		// ...by parsing msg?
		return err
	case params.IsCodeStorageAttached(err):
		return err
	case params.IsCodeNotSupported(err):
		return errors.NewNotSupported(nil, msg)
	case params.IsBadRequest(err):
		return errors.NewBadRequest(nil, msg)
	case params.IsMethodNotAllowed(err):
		return errors.NewMethodNotAllowed(nil, msg)
	case params.ErrCode(err) == params.CodeDischargeRequired:
		// TODO(ericsnow) Handle DischargeRequiredError here.
		return err
	default:
		return err
	}
}
1333275
func NewONSError(e error, description string) *ONSError {
	err := &ONSError{RootError: e}
	err.AddParameter("ErrorDescription", description)
	return err
}
944294
func (s *ActivityScheduleFailedEventDetails) SetError(v string) *ActivityScheduleFailedEventDetails {
	s.Error = &v
	return s
}
912082
func IsUnexpectedError(err error) bool {
	return yarpcerrors.FromError(err).Code() == yarpcerrors.CodeInternal
}
1332434
func replyError(c context.Context, rw http.ResponseWriter, err error, msg string, args ...interface{}) {
	code := http.StatusBadRequest
	if transient.Tag.In(err) {
		code = http.StatusInternalServerError
	}
	msg = fmt.Sprintf(msg, args...)
	logging.Errorf(c, "HTTP %d: %s", code, msg)
	http.Error(rw, msg, code)
}
390501
func (c *Client) UseError(fn context.HandlerFunc) *Client {
	c.Middleware.UseError(fn)
	return c
}
1070982
func (s *AssessmentRunNotification) SetError(v bool) *AssessmentRunNotification {
	s.Error = &v
	return s
}
465170
func httpError(status int, format string, a ...interface{}) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, fmt.Sprintf(format, a...), http.StatusInternalServerError)
	})
}
362608
func (r *Router) handleError(c *Context, err error) {
	if httpError, ok := err.(HTTPError); ok {
		c.Error(httpError.Error(), httpError.StatusCode())
	} else {
		c.Error(err.Error(), http.StatusInternalServerError)
	}
}
369537
func RequestError(level string, r *http.Request, err error) {
	std.RequestError(level, r, err)
}
746905
func Error(ctx context.Context, msg string, logCtx ...interface{}) {
	FromContext(ctx).Error(msg, logCtx...)
}
462030
func (self *stateObject) setError(err error) {
	if self.dbErr == nil {
		self.dbErr = err
	}
}
362790
func (s *BulkEmailDestinationStatus) SetError(v string) *BulkEmailDestinationStatus {
	s.Error = &v
	return s
}
188762
func IsError(err error, code int) bool {
	perr, ok := err.(*Err)
	return ok && perr.c == code
}