diff options
author | Ayke van Laethem <[email protected]> | 2019-06-29 19:04:35 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-06-29 19:18:46 +0200 |
commit | a328bbdff3035c31c1bd0b16618eabd4ab757b9e (patch) | |
tree | 6ac371280d3b6c40107b0673de0002c47838c71d | |
parent | 4ecd478d828498840080356a8684cce2d61494dc (diff) | |
download | tinygo-a328bbdff3035c31c1bd0b16618eabd4ab757b9e.tar.gz tinygo-a328bbdff3035c31c1bd0b16618eabd4ab757b9e.zip |
main: small refactor in error printing
Use a type switch instead of an if/else chain. This results in much more
readable code.
-rw-r--r-- | main.go | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -558,23 +558,24 @@ func usage() { func handleCompilerError(err error) { if err != nil { - if errUnsupported, ok := err.(*interp.Unsupported); ok { + switch err := err.(type) { + case *interp.Unsupported: // hit an unknown/unsupported instruction fmt.Fprintln(os.Stderr, "unsupported instruction during init evaluation:") - errUnsupported.Inst.Dump() + err.Inst.Dump() fmt.Fprintln(os.Stderr) - } else if errCompiler, ok := err.(types.Error); ok { - fmt.Fprintln(os.Stderr, errCompiler) - } else if errLoader, ok := err.(loader.Errors); ok { - fmt.Fprintln(os.Stderr, "#", errLoader.Pkg.ImportPath) - for _, err := range errLoader.Errs { + case types.Error: + fmt.Fprintln(os.Stderr, err) + case loader.Errors: + fmt.Fprintln(os.Stderr, "#", err.Pkg.ImportPath) + for _, err := range err.Errs { fmt.Fprintln(os.Stderr, err) } - } else if errMulti, ok := err.(*multiError); ok { - for _, err := range errMulti.Errs { + case *multiError: + for _, err := range err.Errs { fmt.Fprintln(os.Stderr, err) } - } else { + default: fmt.Fprintln(os.Stderr, "error:", err) } os.Exit(1) |