WithDetails returns a new status with the provided details messages appended to the status. If any errors are encountered, it returns nil and the first error encountered.
(details ...protoadapt.MessageV1)
| 132 | // WithDetails returns a new status with the provided details messages appended to the status. |
| 133 | // If any errors are encountered, it returns nil and the first error encountered. |
| 134 | func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) { |
| 135 | if s.Code() == codes.OK { |
| 136 | return nil, errors.New("no error details for status with code OK") |
| 137 | } |
| 138 | // s.Code() != OK implies that s.Proto() != nil. |
| 139 | p := s.Proto() |
| 140 | for _, detail := range details { |
| 141 | m, err := anypb.New(protoadapt.MessageV2Of(detail)) |
| 142 | if err != nil { |
| 143 | return nil, err |
| 144 | } |
| 145 | p.Details = append(p.Details, m) |
| 146 | } |
| 147 | return &Status{s: p}, nil |
| 148 | } |
| 149 | |
| 150 | // Details returns a slice of details messages attached to the status. |
| 151 | // If a detail cannot be decoded, the error is returned in place of the detail. |