Better error messages (#24)

* Print proper error messages while using contract subcommands and also exit with status code 1.

* Make -in a flag, also remove dot from avm extension.

* Work on feedback by Anthony.

* Update README and VERSION
This commit is contained in:
Pawan Rawal 2018-02-24 20:10:45 +11:00 committed by Anthony De Meulemeester
parent 23cfebf621
commit e93dfe8062
6 changed files with 43 additions and 18 deletions

View file

@ -3,7 +3,6 @@ package compiler
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"go/ast"
"go/build"
@ -114,10 +113,10 @@ func resolveImports(f *ast.File) (map[string]*archive, error) {
// CompileAndSave will compile and save the file to disk.
func CompileAndSave(src string, o *Options) error {
if !strings.HasSuffix(src, ".go") {
return fmt.Errorf("%s is not a Go file", src)
}
if len(o.Outfile) == 0 {
if !strings.HasSuffix(src, ".go") {
return errors.New("not a Go file")
}
o.Outfile = strings.TrimSuffix(src, ".go")
}
if len(o.Ext) == 0 {
@ -129,7 +128,7 @@ func CompileAndSave(src string, o *Options) error {
}
b, err = Compile(bytes.NewReader(b), o)
if err != nil {
return err
return fmt.Errorf("Error while trying to compile smart contract file: %v", err)
}
if o.Debug {
log.Println(hex.EncodeToString(b))