@@ -3,13 +3,16 @@ package dsl
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "encoding/json"
6
7
"io"
7
8
"os"
8
9
"path/filepath"
9
10
10
11
"github.com/pkg/errors"
12
+ "github.com/vim-volt/volt/config"
11
13
"github.com/vim-volt/volt/dsl/dslctx"
12
14
"github.com/vim-volt/volt/dsl/types"
15
+ "github.com/vim-volt/volt/lockjson"
13
16
"github.com/vim-volt/volt/pathutil"
14
17
"github.com/vim-volt/volt/transaction"
15
18
)
@@ -38,7 +41,7 @@ func Execute(ctx context.Context, expr types.Expr) (_ types.Value, result error)
38
41
}
39
42
40
43
// Write given expression to $VOLTPATH/trx/lock/log.json
41
- err = writeExpr ( expr )
44
+ err = writeTrxLog ( ctx , expr )
42
45
if err != nil {
43
46
return nil , err
44
47
}
@@ -63,18 +66,32 @@ func expandMacro(expr types.Expr) (types.Expr, error) {
63
66
return result , nil
64
67
}
65
68
66
- func writeExpr ( expr types.Expr ) error {
69
+ func writeTrxLog ( ctx context. Context , expr types.Expr ) error {
67
70
deparsed , err := Deparse (expr )
68
71
if err != nil {
69
72
return errors .Wrap (err , "failed to deparse expression" )
70
73
}
71
74
75
+ type contentT struct {
76
+ Expr interface {} `json:"expr"`
77
+ Config * config.Config `json:"config"`
78
+ LockJSON * lockjson.LockJSON `json:"lockjson"`
79
+ }
80
+ content , err := json .Marshal (& contentT {
81
+ Expr : deparsed ,
82
+ Config : ctx .Value (dslctx .ConfigKey ).(* config.Config ),
83
+ LockJSON : ctx .Value (dslctx .LockJSONKey ).(* lockjson.LockJSON ),
84
+ })
85
+ if err != nil {
86
+ return errors .Wrap (err , "failed to marshal as JSON" )
87
+ }
88
+
72
89
filename := filepath .Join (pathutil .TrxDir (), "lock" , "log.json" )
73
90
logFile , err := os .Create (filename )
74
91
if err != nil {
75
92
return errors .Wrapf (err , "could not create %s" , filename )
76
93
}
77
- _ , err = io .Copy (logFile , bytes .NewReader (deparsed ))
94
+ _ , err = io .Copy (logFile , bytes .NewReader (content ))
78
95
if err != nil {
79
96
return errors .Wrapf (err , "failed to write transaction log %s" , filename )
80
97
}
0 commit comments