-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
33 lines (28 loc) · 829 Bytes
/
error.go
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
29
30
31
32
33
package log_v1
import (
"fmt"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type ErrOffsetOutOfRange struct {
Offset uint64
}
// This method needs to be called GRPCStatus() only and nothing else.
func (e ErrOffsetOutOfRange) GRPCStatus() *status.Status {
st := status.New(codes.NotFound, fmt.Sprintf("offset out of range: %d", e.Offset))
msg := fmt.Sprintf("The requested offset is outside the log's range: %d", e.Offset)
d := &errdetails.LocalizedMessage{
Locale: "en-US",
Message: msg,
}
std, err := st.WithDetails(d)
if err != nil {
return st
}
return std
}
// This method is required to make ErrOffsetOutOfRange satisfy the error interface.
func (e ErrOffsetOutOfRange) Error() string {
return e.GRPCStatus().Err().Error()
}