forked from cerc-io/plugeth
cmd/evm: change error msg output to stderr (#17118)
* cmd/evm: change error msg output to stderr * cmd/evm: fix some linter error
This commit is contained in:
parent
d927cbb638
commit
fb9f7261ec
@ -50,6 +50,6 @@ func compileCmd(ctx *cli.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(bin)
|
fmt.Fprintln(ctx.App.Writer, bin)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,6 @@ func disasmCmd(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code := strings.TrimSpace(string(in[:]))
|
code := strings.TrimSpace(string(in[:]))
|
||||||
fmt.Printf("%v\n", code)
|
fmt.Fprintf(ctx.App.Writer, "%v\n", code)
|
||||||
return asm.PrintDisassembled(code)
|
return asm.PrintDisassembled(code)
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,11 @@ func Compile(fn string, src []byte, debug bool) (string, error) {
|
|||||||
bin, compileErrors := compiler.Compile()
|
bin, compileErrors := compiler.Compile()
|
||||||
if len(compileErrors) > 0 {
|
if len(compileErrors) > 0 {
|
||||||
// report errors
|
// report errors
|
||||||
|
errs := ""
|
||||||
for _, err := range compileErrors {
|
for _, err := range compileErrors {
|
||||||
fmt.Printf("%s:%v\n", fn, err)
|
errs += fmt.Sprintf("%s:%v\n", fn, err)
|
||||||
}
|
}
|
||||||
return "", errors.New("compiling failed")
|
return "", errors.New(errs + "compiling failed\n")
|
||||||
}
|
}
|
||||||
return bin, nil
|
return bin, nil
|
||||||
}
|
}
|
||||||
|
@ -128,13 +128,13 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
if ctx.GlobalString(CodeFileFlag.Name) == "-" {
|
if ctx.GlobalString(CodeFileFlag.Name) == "-" {
|
||||||
//Try reading from stdin
|
//Try reading from stdin
|
||||||
if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil {
|
if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil {
|
||||||
fmt.Printf("Could not load code from stdin: %v\n", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "Could not load code from stdin: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Codefile with hex assembly
|
// Codefile with hex assembly
|
||||||
if hexcode, err = ioutil.ReadFile(ctx.GlobalString(CodeFileFlag.Name)); err != nil {
|
if hexcode, err = ioutil.ReadFile(ctx.GlobalString(CodeFileFlag.Name)); err != nil {
|
||||||
fmt.Printf("Could not load code from file: %v\n", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "Could not load code from file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,11 +172,11 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
if cpuProfilePath := ctx.GlobalString(CPUProfileFlag.Name); cpuProfilePath != "" {
|
if cpuProfilePath := ctx.GlobalString(CPUProfileFlag.Name); cpuProfilePath != "" {
|
||||||
f, err := os.Create(cpuProfilePath)
|
f, err := os.Create(cpuProfilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("could not create CPU profile: ", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "could not create CPU profile: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := pprof.StartCPUProfile(f); err != nil {
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||||||
fmt.Println("could not start CPU profile: ", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "could not start CPU profile: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
@ -200,17 +200,17 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
|
|
||||||
if ctx.GlobalBool(DumpFlag.Name) {
|
if ctx.GlobalBool(DumpFlag.Name) {
|
||||||
statedb.IntermediateRoot(true)
|
statedb.IntermediateRoot(true)
|
||||||
fmt.Println(string(statedb.Dump()))
|
fmt.Fprintln(ctx.App.Writer, string(statedb.Dump()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if memProfilePath := ctx.GlobalString(MemProfileFlag.Name); memProfilePath != "" {
|
if memProfilePath := ctx.GlobalString(MemProfileFlag.Name); memProfilePath != "" {
|
||||||
f, err := os.Create(memProfilePath)
|
f, err := os.Create(memProfilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("could not create memory profile: ", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "could not create memory profile: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||||
fmt.Println("could not write memory profile: ", err)
|
fmt.Fprintf(ctx.App.ErrWriter, "could not create memory profile: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
@ -218,17 +218,17 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
|
|
||||||
if ctx.GlobalBool(DebugFlag.Name) {
|
if ctx.GlobalBool(DebugFlag.Name) {
|
||||||
if debugLogger != nil {
|
if debugLogger != nil {
|
||||||
fmt.Fprintln(os.Stderr, "#### TRACE ####")
|
fmt.Fprintln(ctx.App.ErrWriter, "#### TRACE ####")
|
||||||
vm.WriteTrace(os.Stderr, debugLogger.StructLogs())
|
vm.WriteTrace(ctx.App.ErrWriter, debugLogger.StructLogs())
|
||||||
}
|
}
|
||||||
fmt.Fprintln(os.Stderr, "#### LOGS ####")
|
fmt.Fprintln(ctx.App.ErrWriter, "#### LOGS ####")
|
||||||
vm.WriteLogs(os.Stderr, statedb.Logs())
|
vm.WriteLogs(ctx.App.ErrWriter, statedb.Logs())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.GlobalBool(StatDumpFlag.Name) {
|
if ctx.GlobalBool(StatDumpFlag.Name) {
|
||||||
var mem goruntime.MemStats
|
var mem goruntime.MemStats
|
||||||
goruntime.ReadMemStats(&mem)
|
goruntime.ReadMemStats(&mem)
|
||||||
fmt.Fprintf(os.Stderr, `evm execution time: %v
|
fmt.Fprintf(ctx.App.ErrWriter, `evm execution time: %v
|
||||||
heap objects: %d
|
heap objects: %d
|
||||||
allocations: %d
|
allocations: %d
|
||||||
total allocations: %d
|
total allocations: %d
|
||||||
@ -238,9 +238,9 @@ Gas used: %d
|
|||||||
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC, initialGas-leftOverGas)
|
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC, initialGas-leftOverGas)
|
||||||
}
|
}
|
||||||
if tracer == nil {
|
if tracer == nil {
|
||||||
fmt.Printf("0x%x\n", ret)
|
fmt.Fprintf(ctx.App.Writer, "0x%x\n", ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(" error: %v\n", err)
|
fmt.Fprintf(ctx.App.ErrWriter, " error: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func stateTestCmd(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
// print state root for evmlab tracing (already committed above, so no need to delete objects again
|
// print state root for evmlab tracing (already committed above, so no need to delete objects again
|
||||||
if ctx.GlobalBool(MachineFlag.Name) && state != nil {
|
if ctx.GlobalBool(MachineFlag.Name) && state != nil {
|
||||||
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%x\"}\n", state.IntermediateRoot(false))
|
fmt.Fprintf(ctx.App.ErrWriter, "{\"stateRoot\": \"%x\"}\n", state.IntermediateRoot(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, *result)
|
results = append(results, *result)
|
||||||
@ -115,13 +115,13 @@ func stateTestCmd(ctx *cli.Context) error {
|
|||||||
// Print any structured logs collected
|
// Print any structured logs collected
|
||||||
if ctx.GlobalBool(DebugFlag.Name) {
|
if ctx.GlobalBool(DebugFlag.Name) {
|
||||||
if debugger != nil {
|
if debugger != nil {
|
||||||
fmt.Fprintln(os.Stderr, "#### TRACE ####")
|
fmt.Fprintln(ctx.App.ErrWriter, "#### TRACE ####")
|
||||||
vm.WriteTrace(os.Stderr, debugger.StructLogs())
|
vm.WriteTrace(ctx.App.ErrWriter, debugger.StructLogs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out, _ := json.MarshalIndent(results, "", " ")
|
out, _ := json.MarshalIndent(results, "", " ")
|
||||||
fmt.Println(string(out))
|
fmt.Fprintln(ctx.App.Writer, string(out))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user