Add panic recover to ffi
This commit is contained in:
@@ -3,8 +3,10 @@ package shared
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/sagernet/sing-box/option"
|
||||
)
|
||||
@@ -20,3 +22,10 @@ func SaveCurrentConfig(path string, options option.Options) error {
|
||||
}
|
||||
return os.WriteFile(filepath.Join(path, "current-config.json"), buffer.Bytes(), 0777)
|
||||
}
|
||||
|
||||
func DeferPanicToError(name string, err func(error)) {
|
||||
if r := recover(); r != nil {
|
||||
s := fmt.Errorf("%s panic: %s\n%s", name, r, string(debug.Stack()))
|
||||
err(s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user