summaryrefslogtreecommitdiff
path: root/internal/commands/util.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2022-08-09 07:50:12 +1000
committerGitHub <noreply@github.com>2022-08-09 07:50:12 +1000
commit342497a86901ec7ce8b290b472c3cca2c25ec97a (patch)
tree8c740c014e4f016535c09c543c050f1d9bc64450 /internal/commands/util.go
parenta59a3c62f985bd276859a2b6c161411a1a8d9a73 (diff)
refactor(server): use errgroup to supervise services (#3755)
Uses the errgroup package and pattern for supervising services like servers etc.
Diffstat (limited to 'internal/commands/util.go')
-rw-r--r--internal/commands/util.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/commands/util.go b/internal/commands/util.go
new file mode 100644
index 000000000..26c308648
--- /dev/null
+++ b/internal/commands/util.go
@@ -0,0 +1,18 @@
+package commands
+
+import (
+ "fmt"
+)
+
+func recoverErr(i interface{}) error {
+ switch v := i.(type) {
+ case nil:
+ return nil
+ case string:
+ return fmt.Errorf("recovered panic: %s", v)
+ case error:
+ return fmt.Errorf("recovered panic: %w", v)
+ default:
+ return fmt.Errorf("recovered panic with unknown type: %v", v)
+ }
+}