mcfg: make sure Populate never returns a nil context

This commit is contained in:
Brian Picciano 2019-04-29 20:58:13 -04:00
parent 8db9e78e08
commit a07df614d8

View File

@ -94,10 +94,11 @@ func Populate(ctx context.Context, src Source) (context.Context, error) {
if src == nil { if src == nil {
src = ParamValues(nil) src = ParamValues(nil)
} }
ogCtx := ctx
ctx, pvs, err := src.Parse(ctx) ctx, pvs, err := src.Parse(ctx)
if err != nil { if err != nil {
return nil, err return ogCtx, err
} }
// map Params to their hash, so we can match them to their ParamValues. // map Params to their hash, so we can match them to their ParamValues.
@ -131,7 +132,7 @@ func Populate(ctx context.Context, src Source) (context.Context, error) {
} else if _, ok := pvM[hash]; !ok { } else if _, ok := pvM[hash]; !ok {
ctx := mctx.Annotate(p.Context, ctx := mctx.Annotate(p.Context,
"param", paramFullName(mctx.Path(p.Context), p.Name)) "param", paramFullName(mctx.Path(p.Context), p.Name))
return nil, merr.New("required parameter is not set", ctx) return ogCtx, merr.New("required parameter is not set", ctx)
} }
} }
@ -140,7 +141,7 @@ func Populate(ctx context.Context, src Source) (context.Context, error) {
// at this point, all ParamValues in pvM have a corresponding pM Param // at this point, all ParamValues in pvM have a corresponding pM Param
p := pM[hash] p := pM[hash]
if err := json.Unmarshal(pv.Value, p.Into); err != nil { if err := json.Unmarshal(pv.Value, p.Into); err != nil {
return nil, err return ogCtx, err
} }
} }