-
Notifications
You must be signed in to change notification settings - Fork 671
/
errors.go
35 lines (30 loc) · 1.26 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpcchainvm
import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
vmpb "github.com/ava-labs/avalanchego/proto/pb/vm"
)
var (
errEnumToError = map[vmpb.Error]error{
vmpb.Error_ERROR_CLOSED: database.ErrClosed,
vmpb.Error_ERROR_NOT_FOUND: database.ErrNotFound,
vmpb.Error_ERROR_HEIGHT_INDEX_NOT_IMPLEMENTED: block.ErrHeightIndexedVMNotImplemented,
vmpb.Error_ERROR_HEIGHT_INDEX_INCOMPLETE: block.ErrIndexIncomplete,
vmpb.Error_ERROR_STATE_SYNC_NOT_IMPLEMENTED: block.ErrStateSyncableVMNotImplemented,
}
errorToErrEnum = map[error]vmpb.Error{
database.ErrClosed: vmpb.Error_ERROR_CLOSED,
database.ErrNotFound: vmpb.Error_ERROR_NOT_FOUND,
block.ErrHeightIndexedVMNotImplemented: vmpb.Error_ERROR_HEIGHT_INDEX_NOT_IMPLEMENTED,
block.ErrIndexIncomplete: vmpb.Error_ERROR_HEIGHT_INDEX_INCOMPLETE,
block.ErrStateSyncableVMNotImplemented: vmpb.Error_ERROR_STATE_SYNC_NOT_IMPLEMENTED,
}
)
func errorToRPCError(err error) error {
if _, ok := errorToErrEnum[err]; ok {
return nil
}
return err
}