[NOD-335] Don't print stack-trace when cli flags are invalid (#416)

* [NOD-335] Made it not write a stack trace if the command line flags are wrong.

* [NOD-335] Fixed panic not printing the right error.

* [NOD-335] Removed code duplication.
This commit is contained in:
stasatdaglabs 2019-09-18 17:22:32 +03:00 committed by Ori Newman
parent d4083cbdbe
commit 850876e6a7
2 changed files with 7 additions and 2 deletions

View File

@ -45,7 +45,6 @@ func Parse() (*Config, error) {
}
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
_, err := parser.Parse()
if err != nil {
return nil, err
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"github.com/daglabs/btcd/apiserver/config"
"github.com/daglabs/btcd/apiserver/database"
@ -20,7 +21,12 @@ func main() {
cfg, err := config.Parse()
if err != nil {
panic(fmt.Errorf("Error parsing command-line arguments: %s", err))
errString := fmt.Sprintf("Error parsing command-line arguments: %s", err)
_, fErr := fmt.Fprintf(os.Stderr, errString)
if fErr != nil {
panic(errString)
}
return
}
if cfg.Migrate {