2023-02-09 19:18:06 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-03-10 21:31:24 +00:00
|
|
|
|
2023-02-09 19:18:06 +00:00
|
|
|
"x-ui/logger"
|
|
|
|
)
|
|
|
|
|
2025-03-12 19:13:51 +00:00
|
|
|
func NewErrorf(format string, a ...any) error {
|
2023-02-09 19:18:06 +00:00
|
|
|
msg := fmt.Sprintf(format, a...)
|
|
|
|
return errors.New(msg)
|
|
|
|
}
|
|
|
|
|
2025-03-12 19:13:51 +00:00
|
|
|
func NewError(a ...any) error {
|
2023-02-09 19:18:06 +00:00
|
|
|
msg := fmt.Sprintln(a...)
|
|
|
|
return errors.New(msg)
|
|
|
|
}
|
|
|
|
|
2025-03-12 19:13:51 +00:00
|
|
|
func Recover(msg string) any {
|
2023-02-09 19:18:06 +00:00
|
|
|
panicErr := recover()
|
|
|
|
if panicErr != nil {
|
|
|
|
if msg != "" {
|
|
|
|
logger.Error(msg, "panic:", panicErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return panicErr
|
|
|
|
}
|