mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
replace os.Exit with panic for logger.CriticalIf (#6065)
This commit prevents complete server failures caused by `logger.CriticalIf` calls. Instead of calling `os.Exit(1)` the function now executes a panic with a special value indicating that a critical error happend. At the top HTTP handler layer panics are recovered and if its a critical error the client gets an InternalServerError status code. Further this allows unit tests to cover critical-error code paths.
This commit is contained in:
committed by
kannappanr
parent
5fbdd70de9
commit
cd152f404a
@@ -362,13 +362,15 @@ func LogIf(ctx context.Context, err error) {
|
||||
fmt.Println(output)
|
||||
}
|
||||
|
||||
// CriticalIf :
|
||||
// Like LogIf with exit
|
||||
// It'll be called for fatal error conditions during run-time
|
||||
// ErrCritical is the value panic'd whenever CriticalIf is called.
|
||||
var ErrCritical struct{}
|
||||
|
||||
// CriticalIf logs the provided error on the console. It fails the
|
||||
// current go-routine by causing a `panic(ErrCritical)`.
|
||||
func CriticalIf(ctx context.Context, err error) {
|
||||
if err != nil {
|
||||
LogIf(ctx, err)
|
||||
os.Exit(1)
|
||||
panic(ErrCritical)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user