mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-14 15:02:01 -04:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info> Signed-off-by: Christian Mesh <christianmesh1@gmail.com> Signed-off-by: James Humphries <James@james-humphries.co.uk> Co-authored-by: James Humphries <jamesh@spacelift.io> Co-authored-by: Serdar Dalgıç <serdardalgic@users.noreply.github.com> Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info> Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
27 lines
562 B
Go
27 lines
562 B
Go
package aesgcm
|
|
|
|
import "fmt"
|
|
|
|
// handlePanic runs the specified function and returns its result value or returned error. If a panic occurs, it returns the
|
|
// panic as an error.
|
|
func handlePanic(f func() ([]byte, error)) (result []byte, err error) {
|
|
result, e := func() ([]byte, error) {
|
|
defer func() {
|
|
var ok bool
|
|
e := recover()
|
|
if e == nil {
|
|
return
|
|
}
|
|
if err, ok = e.(error); !ok {
|
|
// In case the panic is not an error
|
|
err = fmt.Errorf("%v", e)
|
|
}
|
|
}()
|
|
return f()
|
|
}()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result, e
|
|
}
|