File: status.go

package info (click to toggle)
golang-github-influxdata-yarpc 0.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package status

import (
	"fmt"

	"github.com/influxdata/yarpc/codes"
)

func (m *Status) Error() string {
	return fmt.Sprintf("rpc error: code = %s desc = %s", m.Code, m.Message)
}

// FromError returns a Status representing err if it was produced from this
// package, otherwise it returns nil, false.
func FromError(err error) (s *Status, ok bool) {
	if err == nil {
		return &Status{Code: codes.OK}, true
	}
	if s, ok := err.(*Status); ok {
		return s, true
	}
	return nil, false
}

// Errorf returns Error(c, fmt.Sprintf(format, a...)).
func Errorf(c codes.Code, format string, a ...interface{}) error {
	return &Status{Code: c, Message: fmt.Sprintf(format, a...)}
}