From bac721bf1e56d93d1d98a671b76a416bd6da9096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 13 Jul 2022 09:12:08 +0200 Subject: [PATCH] fix: improve error reporting when port is in use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, when we could not start listening on webserver's TCP port, 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š --- main/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/main.go b/main/main.go index 0331a2c..02fefcc 100644 --- a/main/main.go +++ b/main/main.go @@ -58,7 +58,8 @@ func main() { nl, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { - panic(err) + fmt.Fprintf(os.Stderr, "Cannot start the webserver: %s\n", err.Error()) + os.Exit(4) } go func() {