package core

import (
	"github.com/jeanhua/AniaBot/common/plugin"
)

func safeExecuteWithReturn[T any](label string, p plugin.Plugin, f func(p plugin.Plugin) T) T {
	defer func() {
		if err := recover(); err != nil {
			Logger().Error("插件触发错误", "label", label, "plugin", p.GetMeta().Name, "error", err)
		}
	}()
	return f(p)
}

func safeExecute(label string, p plugin.Plugin, f func(p plugin.Plugin)) {
	defer func() {
		if err := recover(); err != nil {
			Logger().Error("插件触发错误", "label", label, "plugin", p.GetMeta().Name, "error", err)
		}
	}()
	f(p)
}
