github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/utils/handle_panic.go (about)

     1  package utils
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"runtime/debug"
     7  
     8  	"github.com/ncruces/zenity"
     9  )
    10  
    11  func HandlePanic(appName, msg string, err error) {
    12  	// Create user-friendly error message
    13  	body := fmt.Sprintf(`%v has encountered a fatal error and can't continue. The error message is:
    14  
    15  %v
    16  
    17  The following information might help you in fixing the problem:
    18  
    19  %v
    20  
    21  Strack trace:
    22  
    23  %v`,
    24  		appName,
    25  		Capitalize(msg),
    26  		Capitalize(err.Error()),
    27  		string(debug.Stack()),
    28  	)
    29  
    30  	// Show error message visually using a dialog
    31  	if err := zenity.Error(
    32  		body,
    33  		zenity.Title("Fatal error"),
    34  		zenity.Width(320),
    35  	); err != nil {
    36  		log.Println("could not display fatal error dialog:", err)
    37  	}
    38  
    39  	// Log error message and exit with non-zero exit code
    40  	log.Fatalln(body)
    41  }