Skip to content

Commit 31449a2

Browse files
committed
fix: context is not passed to rollback function
1 parent 464b73f commit 31449a2

14 files changed

+27
-25
lines changed

dsl/execute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ func Execute(ctx context.Context, expr types.Expr) (_ types.Value, result error)
5050
val, rollback, err := evalDepthFirst(ctx, expr)
5151
if err != nil {
5252
if rollback != nil {
53-
rollback()
53+
rollback(ctx)
5454
}
5555
return nil, errors.Wrap(err, "expression returned an error")
5656
}
5757
return val, nil
5858
}
5959

60-
func evalDepthFirst(ctx context.Context, expr types.Expr) (_ types.Value, _ func(), result error) {
60+
func evalDepthFirst(ctx context.Context, expr types.Expr) (_ types.Value, _ func(context.Context), result error) {
6161
op := expr.Op()
6262
g := util.FuncGuard(op.String())
6363
defer func() {

dsl/ops/func_do.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (*doOp) InvertExpr(ctx context.Context, args []types.Value) (types.Value, e
4343
return DoOp.Bind(newargs...)
4444
}
4545

46-
func (*doOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(), result error) {
46+
func (*doOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(context.Context), result error) {
4747
g := util.FuncGuard(DoOp.String())
4848
defer func() {
4949
result = g.Error(recover())

dsl/ops/func_lockjson_write.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (*lockJSONWriteOp) InvertExpr(_ context.Context, args []types.Value) (types
3333
return LockJSONWriteOp.Bind(args...)
3434
}
3535

36-
func (*lockJSONWriteOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(), result error) {
36+
func (*lockJSONWriteOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(context.Context), result error) {
3737
lockJSON := ctx.Value(dslctx.LockJSONKey).(*lockjson.LockJSON)
3838
result = lockJSON.Write()
3939
if result != nil {

dsl/ops/func_migrate_plugconf_config_func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (*migratePlugconfConfigFuncOp) InvertExpr(_ context.Context, args []types.V
4444
return MigratePlugconfConfigFuncOp.Bind(args...)
4545
}
4646

47-
func (*migratePlugconfConfigFuncOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(), result error) {
47+
func (*migratePlugconfConfigFuncOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _ func(context.Context), result error) {
4848
lockJSON := ctx.Value(dslctx.LockJSONKey).(*lockjson.LockJSON)
4949
cfg := ctx.Value(dslctx.ConfigKey).(*config.Config)
5050

dsl/ops/macro.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (*macroBase) IsMacro() bool {
1717
}
1818

1919
// macroInvertExpr inverts the result of op.Execute() which expands an expression
20-
func (*macroBase) macroInvertExpr(ctx context.Context, val types.Value, _ func(), err error) (types.Value, error) {
20+
func (*macroBase) macroInvertExpr(ctx context.Context, val types.Value, _ func(context.Context), err error) (types.Value, error) {
2121
if err != nil {
2222
return nil, err
2323
}

dsl/ops/macro_array.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ func (*arrayOp) Bind(args ...types.Value) (types.Expr, error) {
2727
return expr, nil
2828
}
2929

30-
func (*arrayOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
30+
func (*arrayOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(context.Context), error) {
3131
return types.NewArray(args, types.AnyValue), nil, nil
3232
}

dsl/ops/macro_eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (*evalOp) Bind(args ...types.Value) (types.Expr, error) {
2828
return expr, nil
2929
}
3030

31-
func (*evalOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
31+
func (*evalOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(context.Context), error) {
3232
if err := util.Signature(types.AnyValue).Check(args); err != nil {
3333
return nil, nil, err
3434
}

dsl/ops/macro_invert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (*invertOp) Bind(args ...types.Value) (types.Expr, error) {
2828
return expr, nil
2929
}
3030

31-
func (*invertOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
31+
func (*invertOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(context.Context), error) {
3232
if err := util.Signature(types.AnyValue).Check(args); err != nil {
3333
return nil, nil, err
3434
}

dsl/ops/util/guard.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package util
22

33
import (
4+
"context"
45
"fmt"
6+
57
"github.com/pkg/errors"
68
)
79

@@ -24,10 +26,10 @@ type Guard interface {
2426
Error(v interface{}) error
2527

2628
// Rollback calls rollback functions in reversed order
27-
Rollback()
29+
Rollback(ctx context.Context)
2830

2931
// Add adds given rollback functions, but skips if f == nil
30-
Add(f func())
32+
Add(f func(context.Context))
3133
}
3234

3335
// FuncGuard returns Guard instance for function
@@ -38,7 +40,7 @@ func FuncGuard(name string) Guard {
3840
type guard struct {
3941
errMsg string
4042
err error
41-
rbFuncs []func()
43+
rbFuncs []func(context.Context)
4244
}
4345

4446
func (g *guard) Error(v interface{}) error {
@@ -50,14 +52,14 @@ func (g *guard) Error(v interface{}) error {
5052
return g.err
5153
}
5254

53-
func (g *guard) Rollback() {
55+
func (g *guard) Rollback(ctx context.Context) {
5456
for i := len(g.rbFuncs) - 1; i >= 0; i-- {
55-
g.rbFuncs[i]()
57+
g.rbFuncs[i](ctx)
5658
}
5759
g.rbFuncs = nil // do not rollback twice
5860
}
5961

60-
func (g *guard) Add(f func()) {
62+
func (g *guard) Add(f func(context.Context)) {
6163
if f != nil {
6264
g.rbFuncs = append(g.rbFuncs, f)
6365
}

dsl/types/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (expr *expr) RetType() Type {
3939
return expr.retType
4040
}
4141

42-
func (expr *expr) Eval(ctx context.Context) (val Value, rollback func(), err error) {
42+
func (expr *expr) Eval(ctx context.Context) (val Value, rollback func(context.Context), err error) {
4343
return expr.op.EvalExpr(ctx, expr.args)
4444
}
4545

0 commit comments

Comments
 (0)