simulation: close opened files and check for error while creating files (#8217)

* Read gentx amount as argument

* Update gentx command usage

* Update gentx tests

* Update docs of gentx

* Close opened files and check for error while creating files

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
This commit is contained in:
Prathyusha Lakkireddy
2020-12-22 13:46:42 +00:00
committed by GitHub
co-authored by Alessio Treglia Anil Kumar Kammari
parent c82febe0e8
commit f9dc082059
+6 -2
View File
@@ -35,6 +35,7 @@ func (lw *StandardLogWriter) AddEntry(opEntry OperationEntry) {
// PrintLogs - print the logs to a simulation file
func (lw *StandardLogWriter) PrintLogs() {
f := createLogFile()
defer f.Close()
for i := 0; i < len(lw.OpEntries); i++ {
writeEntry := fmt.Sprintf("%s\n", (lw.OpEntries[i]).MustMarshal())
@@ -50,7 +51,7 @@ func createLogFile() *os.File {
var f *os.File
fileName := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02_15:04:05"))
folderPath := os.ExpandEnv("$HOME/.simapp/simulations")
folderPath := path.Join(os.ExpandEnv("$HOME"), ".simapp", "simulations")
filePath := path.Join(folderPath, fileName)
err := os.MkdirAll(folderPath, os.ModePerm)
@@ -58,7 +59,10 @@ func createLogFile() *os.File {
panic(err)
}
f, _ = os.Create(filePath)
f, err = os.Create(filePath)
if err != nil {
panic(err)
}
fmt.Printf("Logs to writing to %s\n", filePath)
return f