Skip to content

Commit

Permalink
helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgoStephenAkiki committed Sep 29, 2022
1 parent b43df96 commit a831389
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 1 addition & 5 deletions cmd/conduit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func init() {

// runConduitCmdWithConfig run the main logic with a supplied conduit config
func runConduitCmdWithConfig(cfg *conduit.Config) error {
defer func() {
if r := recover(); r != nil {
logger.Fatalf("conduit framework experienced a panic: %v", r)
}
}()
defer conduit.HandlePanic(logger)

// From docs:
// BindEnv takes one or more parameters. The first parameter is the key name, the rest are the name of the
Expand Down
10 changes: 10 additions & 0 deletions conduit/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package conduit

import log "github.com/sirupsen/logrus"

// HandlePanic function to log panics in a common way
func HandlePanic(logger *log.Logger) {
if r := recover(); r != nil {
logger.Panicf("conduit pipeline experienced a panic: %v", r)
}
}
6 changes: 1 addition & 5 deletions conduit/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ func (p *pipelineImpl) Start() {
go func() {
defer p.wg.Done()
// We need to add a separate recover function here since it launches its own go-routine
defer func() {
if r := recover(); r != nil {
p.logger.Fatalf("conduit pipeline experienced a panic: %v", r)
}
}()
defer HandlePanic(p.logger)
for {
pipelineRun:
select {
Expand Down

0 comments on commit a831389

Please sign in to comment.