@@ -3,13 +3,16 @@ package dsl
33import (
44 "bytes"
55 "context"
6+ "encoding/json"
67 "io"
78 "os"
89 "path/filepath"
910
1011 "github.com/pkg/errors"
12+ "github.com/vim-volt/volt/config"
1113 "github.com/vim-volt/volt/dsl/dslctx"
1214 "github.com/vim-volt/volt/dsl/types"
15+ "github.com/vim-volt/volt/lockjson"
1316 "github.com/vim-volt/volt/pathutil"
1417 "github.com/vim-volt/volt/transaction"
1518)
@@ -38,7 +41,7 @@ func Execute(ctx context.Context, expr types.Expr) (_ types.Value, result error)
3841 }
3942
4043 // Write given expression to $VOLTPATH/trx/lock/log.json
41- err = writeExpr ( expr )
44+ err = writeTrxLog ( ctx , expr )
4245 if err != nil {
4346 return nil , err
4447 }
@@ -63,18 +66,32 @@ func expandMacro(expr types.Expr) (types.Expr, error) {
6366 return result , nil
6467}
6568
66- func writeExpr ( expr types.Expr ) error {
69+ func writeTrxLog ( ctx context. Context , expr types.Expr ) error {
6770 deparsed , err := Deparse (expr )
6871 if err != nil {
6972 return errors .Wrap (err , "failed to deparse expression" )
7073 }
7174
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+
7289 filename := filepath .Join (pathutil .TrxDir (), "lock" , "log.json" )
7390 logFile , err := os .Create (filename )
7491 if err != nil {
7592 return errors .Wrapf (err , "could not create %s" , filename )
7693 }
77- _ , err = io .Copy (logFile , bytes .NewReader (deparsed ))
94+ _ , err = io .Copy (logFile , bytes .NewReader (content ))
7895 if err != nil {
7996 return errors .Wrapf (err , "failed to write transaction log %s" , filename )
8097 }
0 commit comments