Update primary error functions to take a context, deprecate old functions (#1358)
* add new error funcs which take a ctx and deprecate existing funcs * use context where available when writing error events * remove circular internal/errors pkg dep * suppress some chatty errors using errors.WithoutEvent() * convert auth oidc funcs to take context where needed to write events Co-authored-by: Jim <jlambert@hashicorp.com>
This commit is contained in:
1 parent
02ff2db66e
commit
6b78108ecf
227 files changed
+3945
-3736
No files matched your search
+15
-15
@@ -38,15 +38,15 @@ func (q *Queue) Add(m proto.Message, typeName string, t OpType, opt ...Option) e
|
||||
withNullPaths := opts[optionWithSetToNullPaths].([]string)
|
||||
|
||||
if _, ok := m.(ReplayableMessage); !ok {
|
||||
return errors.New(errors.InvalidParameter, op, fmt.Sprintf("%T is not a replayable message", m))
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("%T is not a replayable message", m))
|
||||
}
|
||||
value, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return errors.New(errors.Encode, op, "error marshaling add parameter", errors.WithWrap(err))
|
||||
return errors.NewDeprecated(errors.Encode, op, "error marshaling add parameter", errors.WithWrap(err))
|
||||
}
|
||||
if t == OpType_OP_TYPE_UPDATE {
|
||||
if len(withFieldMasks) == 0 && len(withNullPaths) == 0 {
|
||||
return errors.New(errors.InvalidParameter, op, "missing field masks or null paths for update")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "missing field masks or null paths for update")
|
||||
}
|
||||
fMasks := withFieldMasks
|
||||
if fMasks == nil {
|
||||
@@ -58,10 +58,10 @@ func (q *Queue) Add(m proto.Message, typeName string, t OpType, opt ...Option) e
|
||||
}
|
||||
i, _, _, err := common.Intersection(fMasks, nullPaths)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op)
|
||||
return errors.WrapDeprecated(err, op)
|
||||
}
|
||||
if len(i) != 0 {
|
||||
return errors.New(errors.InvalidParameter, op, fmt.Sprintf("field masks and null paths intersect with: %s", i))
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("field masks and null paths intersect with: %s", i))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,20 +74,20 @@ func (q *Queue) Add(m proto.Message, typeName string, t OpType, opt ...Option) e
|
||||
}
|
||||
data, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return errors.New(errors.Encode, op, "error marshaling message", errors.WithWrap(err))
|
||||
return errors.NewDeprecated(errors.Encode, op, "error marshaling message", errors.WithWrap(err))
|
||||
}
|
||||
q.mx.Lock()
|
||||
defer q.mx.Unlock()
|
||||
err = binary.Write(q, binary.LittleEndian, uint32(len(data)))
|
||||
if err != nil {
|
||||
return errors.New(errors.Io, op, "binary write error", errors.WithWrap(err))
|
||||
return errors.NewDeprecated(errors.Io, op, "binary write error", errors.WithWrap(err))
|
||||
}
|
||||
n, err := q.Write(data)
|
||||
if err != nil {
|
||||
return errors.New(errors.Io, op, "error writing to queue buffer", errors.WithWrap(err))
|
||||
return errors.NewDeprecated(errors.Io, op, "error writing to queue buffer", errors.WithWrap(err))
|
||||
}
|
||||
if n != len(data) {
|
||||
return errors.New(errors.Io, op, fmt.Sprintf("error writing to queue buffer (incorrect number of bytes %d of %d)", n, len(data)))
|
||||
return errors.NewDeprecated(errors.Io, op, fmt.Sprintf("error writing to queue buffer (incorrect number of bytes %d of %d)", n, len(data)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (q *Queue) Add(m proto.Message, typeName string, t OpType, opt ...Option) e
|
||||
func (q *Queue) Remove() (proto.Message, OpType, []string, []string, error) {
|
||||
const op = "oplog.(Queue).Remove"
|
||||
if q.Catalog == nil {
|
||||
return nil, OpType_OP_TYPE_UNSPECIFIED, nil, nil, errors.New(errors.InvalidParameter, op, "nil catalog")
|
||||
return nil, OpType_OP_TYPE_UNSPECIFIED, nil, nil, errors.NewDeprecated(errors.InvalidParameter, op, "nil catalog")
|
||||
}
|
||||
q.mx.Lock()
|
||||
defer q.mx.Unlock()
|
||||
@@ -108,24 +108,24 @@ func (q *Queue) Remove() (proto.Message, OpType, []string, []string, error) {
|
||||
return nil, 0, nil, nil, err // intentionally not wrapping error, return io.EOF so client can handle it correctly
|
||||
}
|
||||
if err != nil {
|
||||
return nil, 0, nil, nil, errors.New(errors.Io, op, "binary read error", errors.WithWrap(err))
|
||||
return nil, 0, nil, nil, errors.NewDeprecated(errors.Io, op, "binary read error", errors.WithWrap(err))
|
||||
}
|
||||
data := q.Next(int(n))
|
||||
msg := new(AnyOperation)
|
||||
err = proto.Unmarshal(data, msg)
|
||||
if err != nil {
|
||||
return nil, 0, nil, nil, errors.New(errors.Decode, op, "error unmarshaling message", errors.WithWrap(err))
|
||||
return nil, 0, nil, nil, errors.NewDeprecated(errors.Decode, op, "error unmarshaling message", errors.WithWrap(err))
|
||||
}
|
||||
if msg.Value == nil {
|
||||
return nil, 0, nil, nil, nil
|
||||
}
|
||||
any, err := q.Catalog.Get(msg.TypeName)
|
||||
if err != nil {
|
||||
return nil, 0, nil, nil, errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("error getting the TypeName: %s", msg.TypeName)))
|
||||
return nil, 0, nil, nil, errors.WrapDeprecated(err, op, errors.WithMsg(fmt.Sprintf("error getting the TypeName: %s", msg.TypeName)))
|
||||
}
|
||||
pm := any.(proto.Message)
|
||||
if err = proto.Unmarshal(msg.Value, pm); err != nil {
|
||||
return nil, 0, nil, nil, errors.New(errors.Decode, op, "error unmarshaling value", errors.WithWrap(err))
|
||||
return nil, 0, nil, nil, errors.NewDeprecated(errors.Decode, op, "error unmarshaling value", errors.WithWrap(err))
|
||||
}
|
||||
var masks, nullPaths []string
|
||||
if msg.OperationType == OpType_OP_TYPE_UPDATE {
|
||||
@@ -136,7 +136,7 @@ func (q *Queue) Remove() (proto.Message, OpType, []string, []string, error) {
|
||||
nullPaths = msg.NullMask.GetPaths()
|
||||
}
|
||||
if len(masks) == 0 && len(nullPaths) == 0 {
|
||||
return nil, 0, nil, nil, errors.New(errors.InvalidParameter, op, "field mask or null paths is required")
|
||||
return nil, 0, nil, nil, errors.NewDeprecated(errors.InvalidParameter, op, "field mask or null paths is required")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user