mirror of https://github.com/status-im/evmc.git
go: Use loader error messages
This commit is contained in:
parent
a304db5c2d
commit
44279f3e71
|
@ -58,7 +58,6 @@ static struct evmc_result execute_wrapper(struct evmc_instance* instance,
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -154,28 +153,18 @@ func Load(filename string) (instance *Instance, err error) {
|
||||||
var loaderErr C.enum_evmc_loader_error_code
|
var loaderErr C.enum_evmc_loader_error_code
|
||||||
handle := C.evmc_load_and_create(cfilename, &loaderErr)
|
handle := C.evmc_load_and_create(cfilename, &loaderErr)
|
||||||
C.free(unsafe.Pointer(cfilename))
|
C.free(unsafe.Pointer(cfilename))
|
||||||
switch loaderErr {
|
|
||||||
case C.EVMC_LOADER_SUCCESS:
|
if loaderErr == C.EVMC_LOADER_SUCCESS {
|
||||||
instance = &Instance{handle}
|
instance = &Instance{handle}
|
||||||
case C.EVMC_LOADER_CANNOT_OPEN:
|
} else {
|
||||||
optionalErrMsg := C.evmc_last_error_msg()
|
errMsg := C.evmc_last_error_msg()
|
||||||
if optionalErrMsg != nil {
|
if errMsg != nil {
|
||||||
msg := C.GoString(optionalErrMsg)
|
err = fmt.Errorf("EVMC loading error: %s", C.GoString(errMsg))
|
||||||
err = fmt.Errorf("evmc loader: %s", msg)
|
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("evmc loader: cannot open %s", filename)
|
err = fmt.Errorf("EVMC loading error %d", int(loaderErr))
|
||||||
}
|
}
|
||||||
case C.EVMC_LOADER_SYMBOL_NOT_FOUND:
|
|
||||||
err = fmt.Errorf("evmc loader: the EVMC create function not found in %s", filename)
|
|
||||||
case C.EVMC_LOADER_INVALID_ARGUMENT:
|
|
||||||
panic("evmc loader: filename argument is invalid")
|
|
||||||
case C.EVMC_LOADER_INSTANCE_CREATION_FAILURE:
|
|
||||||
err = errors.New("evmc loader: VM instance creation failure")
|
|
||||||
case C.EVMC_LOADER_ABI_VERSION_MISMATCH:
|
|
||||||
err = errors.New("evmc loader: ABI version mismatch")
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("evmc loader: unexpected error (%d)", int(loaderErr)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance, err
|
return instance, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue