Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: use os.Exit instead of panic for user errors
Browse files Browse the repository at this point in the history
Before this change, when the user provided incorrect configuration,
the binary produced by GoReleaser would abort with no meaningful
error report:

```
❯ ./build/saturn/l2node-darwin-arm64/saturn-l2
[1]    16654 killed     ./build/saturn/l2node-darwin-arm64/saturn-l2
```

In this commit, I am reworking error handling to print the error to
stderr and exit the process with a non-zero exit code via `os.Exit`.

Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Jul 12, 2022
1 parent 8febc34 commit 9f41f76
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ func main() {
var err error
port, err = strconv.Atoi(portStr)
if err != nil {
panic(fmt.Errorf("Invalid PORT value '%s': %s", portStr, err.Error()))
fmt.Fprintf(os.Stderr, "Invalid PORT value '%s': %s\n", portStr, err.Error())
os.Exit(1)
}
}

filAddr := os.Getenv("FIL_WALLET_ADDRESS")
if filAddr == "" {
panic(errors.New("no FIL_WALLET_ADDRESS provided"))
fmt.Fprintf(os.Stderr, "No FIL_WALLET_ADDRESS provided. Please set the environment variable.\n")
os.Exit(2)
}
if _, err := address.NewFromString(filAddr); err != nil {
panic(fmt.Errorf("invalid FIL_WALLET_ADDRESS format: %s", err.Error()))
fmt.Fprintf(os.Stderr, "Invalid FIL_WALLET_ADDRESS format: %s\n", err.Error())
os.Exit(3)
}
conf, err := json.Marshal(config{FilAddr: filAddr})
if err != nil {
Expand Down

0 comments on commit 9f41f76

Please sign in to comment.