5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 09:30:10 +08:00
wails/v3/pkg/application/errors.go
Fabio Massaioli e7c134de4e
[v3] Late service registration and error handling overhaul (#4066)
* Add service registration method

* Fix error handling and formatting in messageprocessor

* Add configurable error handling

* Improve error strings

* Fix service shutdown on macOS

* Add post shutdown hook

* Better fatal errors

* Add startup/shutdown sequence tests

* Improve debug messages

* Update JS runtime

* Update docs

* Update changelog

* Fix log message in clipboard message processor

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Remove panic in RegisterService

* Fix linux tests (hopefully)

* Fix error formatting everywhere

* Fix typo in windows webview

* Tidy example mods

* Set application name in tests

* Fix ubuntu test workflow

* Cleanup template test pipeline

* Fix dev build detection on Go 1.24

* Update template go.mod/sum to Go 1.24

* Remove redundant caching in template tests

* Final format string cleanup

* Fix wails3 tool references

* Fix legacy log calls

* Remove formatJS and simplify format strings

* Fix indirect import

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-02-19 09:27:41 +01:00

56 lines
1.6 KiB
Go

package application
import (
"fmt"
"os"
"strings"
)
// FatalError instances are passed to the registered error handler
// in case of catastrophic, unrecoverable failures that require immediate termination.
// FatalError wraps the original error value in an informative message.
// The underlying error may be retrieved through the [FatalError.Unwrap] method.
type FatalError struct {
err error
internal bool
}
// Internal returns true when the error was triggered from wails' internal code.
func (e *FatalError) Internal() bool {
return e.internal
}
// Unwrap returns the original cause of the fatal error,
// for easy inspection using the [errors.As] API.
func (e *FatalError) Unwrap() error {
return e.err
}
func (e *FatalError) Error() string {
var buffer strings.Builder
buffer.WriteString("\n\n******************************** FATAL *********************************\n")
buffer.WriteString("* There has been a catastrophic failure in your application. *\n")
if e.internal {
buffer.WriteString("* Please report this error at https://github.com/wailsapp/wails/issues *\n")
}
buffer.WriteString("**************************** Error Details *****************************\n")
buffer.WriteString(e.err.Error())
buffer.WriteString("************************************************************************\n")
return buffer.String()
}
func Fatal(message string, args ...any) {
err := &FatalError{
err: fmt.Errorf(message, args...),
internal: true,
}
if globalApplication != nil {
globalApplication.handleError(err)
} else {
fmt.Println(err)
}
os.Exit(1)
}