summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-08 09:36:24 +0200
committerPaul Buetow <paul@buetow.org>2026-03-08 09:36:24 +0200
commitd5238b199fe592efd6ed9a2c54e4fc475221ff71 (patch)
treed65ce1e4e5cddaa44c41f50f7454759f4172563f
parent77b41ce17090008470c261d1f185da43f76ec0c2 (diff)
task: replace panic-based CLI/runtime exits (task 380)
-rw-r--r--cmd/dcat/main.go4
-rw-r--r--cmd/dgrep/main.go4
-rw-r--r--cmd/dserver/main.go4
-rw-r--r--cmd/dtail/main.go14
-rw-r--r--cmd/dtailhealth/main.go4
5 files changed, 22 insertions, 8 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index 9b8da4f..013baac 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "fmt"
"os"
"github.com/mimecast/dtail/internal/cli"
@@ -62,7 +63,8 @@ func main() {
client, err := clients.NewCatClient(args)
if err != nil {
runtime.Stop()
- panic(err)
+ fmt.Fprintf(os.Stderr, "unable to create dcat client: %v\n", err)
+ os.Exit(1)
}
status := client.Start(runtime.Context(), signal.InterruptCh(runtime.Context()))
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 0e4eb29..121b576 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "fmt"
"os"
"github.com/mimecast/dtail/internal/cli"
@@ -73,7 +74,8 @@ func main() {
client, err := clients.NewGrepClient(args)
if err != nil {
runtime.Stop()
- panic(err)
+ fmt.Fprintf(os.Stderr, "unable to create dgrep client: %v\n", err)
+ os.Exit(1)
}
status := client.Start(runtime.Context(), signal.InterruptCh(runtime.Context()))
diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go
index 4ea3e2b..7c13b29 100644
--- a/cmd/dserver/main.go
+++ b/cmd/dserver/main.go
@@ -73,7 +73,9 @@ func main() {
if pprof != "" {
dlog.Client.Info("Starting PProf", pprof)
go func() {
- panic(http.ListenAndServe(pprof, nil))
+ if err := http.ListenAndServe(pprof, nil); err != nil {
+ dlog.Client.Error("PProf server exited", err)
+ }
}()
}
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index ee34cc5..4ea27df 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -95,6 +95,14 @@ func main() {
}
runtime := cli.NewClientRuntime(baseCtx, profileFlags, "dtail")
+ exitWithError := func(err error) {
+ runtime.Stop()
+ if timeoutCancel != nil {
+ timeoutCancel()
+ }
+ fmt.Fprintf(os.Stderr, "unable to initialize dtail client: %v\n", err)
+ os.Exit(1)
+ }
if checkHealth {
fmt.Println("WARN: DTail health check has moved to separate binary dtailhealth" +
@@ -116,13 +124,11 @@ func main() {
switch args.QueryStr {
case "":
if client, err = clients.NewTailClient(args); err != nil {
- runtime.Stop()
- panic(err)
+ exitWithError(err)
}
default:
if client, err = clients.NewMaprClient(args, clients.DefaultMode); err != nil {
- runtime.Stop()
- panic(err)
+ exitWithError(err)
}
}
diff --git a/cmd/dtailhealth/main.go b/cmd/dtailhealth/main.go
index 3d4cccf..f1fbf6f 100644
--- a/cmd/dtailhealth/main.go
+++ b/cmd/dtailhealth/main.go
@@ -47,7 +47,9 @@ func main() {
if pprof != "" {
dlog.Client.Info("Starting PProf", pprof)
go func() {
- panic(http.ListenAndServe(pprof, nil))
+ if err := http.ListenAndServe(pprof, nil); err != nil {
+ dlog.Client.Error("PProf server exited", err)
+ }
}()
}