Skip to content

Commit

Permalink
Remove unnecessary os.Exit calls
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Dec 12, 2023
1 parent dbe2565 commit 70d6bed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
17 changes: 2 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,13 @@ func (a *App) initConfig() {
if a.options.initComponent.InitConfigParams != nil {
if err := a.options.initComponent.InitConfigParams(a.container); err != nil {
a.LogFatalf("failed to initialize init component config parameters: %s", err)
os.Exit(1)
}
}

forEachComponent(a.options.components, func(component *Component) bool {
if component.InitConfigParams != nil {
if err := component.InitConfigParams(a.container); err != nil {
a.LogFatalf("failed to initialize component (%s) config parameters: %s", component.Name, err)
os.Exit(1)
}
}

Expand Down Expand Up @@ -415,15 +413,13 @@ func (a *App) provide() {
if a.options.initComponent.Provide != nil {
if err := a.options.initComponent.Provide(a.container); err != nil {
a.LogFatalf("provide init component failed: %s", err)
os.Exit(1)
}
}

a.ForEachComponent(func(component *Component) bool {
if component.Provide != nil {
if err := component.Provide(a.container); err != nil {
a.LogFatalf("provide component (%s) failed: %s", component.Name, err)
os.Exit(1)
}
}

Expand All @@ -436,15 +432,13 @@ func (a *App) invoke() {
if a.options.initComponent.DepsFunc != nil {
if err := a.container.Invoke(a.options.initComponent.DepsFunc); err != nil {
a.LogFatalf("invoke init component failed: %s", err)
os.Exit(1)
}
}

a.ForEachComponent(func(component *Component) bool {
if component.DepsFunc != nil {
if err := a.container.Invoke(component.DepsFunc); err != nil {
a.LogFatalf("invoke component (%s) failed: %s", component.Name, err)
os.Exit(1)
}
}

Expand All @@ -459,15 +453,13 @@ func (a *App) configure() {
if a.options.initComponent.Configure != nil {
if err := a.options.initComponent.Configure(); err != nil {
a.LogFatalf("configure init component failed: %s", err)
os.Exit(1)
}
}

a.ForEachComponent(func(component *Component) bool {
if component.Configure != nil {
if err := component.Configure(); err != nil {
a.LogFatalf("configure component (%s) failed: %s", component.Name, err)
os.Exit(1)
}
}
a.LogInfof("Loading components: %s ... done", component.Name)
Expand Down Expand Up @@ -514,7 +506,6 @@ func (a *App) initializeVersionCheck() {
ticker.WaitForGracefulShutdown()
}, math.MaxInt16); err != nil {
a.LogFatalf("failed to start worker: %s", err)
os.Exit(1)
}
}

Expand All @@ -525,7 +516,6 @@ func (a *App) run() {
if a.options.initComponent.Run != nil {
if err := a.options.initComponent.Run(); err != nil {
a.LogFatalf("run init component failed: %s", err)
os.Exit(1)
}
}

Expand All @@ -535,7 +525,6 @@ func (a *App) run() {
if component.Run != nil {
if err := component.Run(); err != nil {
a.LogFatalf("run component (%s) failed: %s", component.Name, err)
os.Exit(1)
}
}

Expand Down Expand Up @@ -569,10 +558,8 @@ func (a *App) Run() {
if r != nil {
if err, ok := r.(error); ok {
a.LogFatalf("application panic, err: %s \n %s", err.Error(), string(debug.Stack()))
os.Exit(1)
}
a.LogFatalf("application panic: %v \n %s", r, string(debug.Stack()))
os.Exit(1)
}
}()
a.initializeApp()
Expand Down Expand Up @@ -723,12 +710,12 @@ func (a *App) LogWarnf(template string, args ...interface{}) {
a.logger.LogWarnf(template, args...)
}

// LogFatal uses fmt.Sprint to construct and log a message.
// LogFatal uses fmt.Sprint to construct and log a message, then calls os.Exit(1).
func (a *App) LogFatal(msg string, args ...interface{}) {
a.logger.LogFatal(msg, args...)
}

// LogFatalf uses fmt.Sprintf to log a templated message.
// LogFatalf uses fmt.Sprintf to log a templated message, then calls os.Exit(1).
func (a *App) LogFatalf(template string, args ...interface{}) {
a.logger.LogFatalf(template, args...)
}
1 change: 0 additions & 1 deletion app/shutdown/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ func (gs *ShutdownHandler) Run() error {
gs.LogWarnf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", int(gs.stopGracePeriod.Seconds())-secondsSinceStart, processList)
} else {
gs.LogFatal("Background processes did not terminate in time! Forcing shutdown ...")
os.Exit(1)
}
}
}()
Expand Down

0 comments on commit 70d6bed

Please sign in to comment.