Repository: cloudwego/kitex
File: pkg/remote/trans_errors.go (Go)

Code before:
 * limitations under the License.
 */

package remote

import (
	"errors"
	"fmt"

	"github.com/cloudwego/kitex/pkg/kerrors"
)

// corresponding with thrift TApplicationException, cannot change it
const (
	UnknownApplicationException = 0
	UnknownMethod               = 1
	InvalidMessageTypeException = 2
	WrongMethodName             = 3
	BadSequenceID               = 4
	MissingResult               = 5
	InternalError               = 6
	ProtocolError               = 7
	InvalidTransform            = 8
	InvalidProtocol             = 9
	UnsupportedClientType       = 10
	UnknownService              = 11
)

var defaultTransErrorMessage = map[int32]string{
	UnknownApplicationException: "unknown application exception",
	UnknownMethod:               "unknown method",
	InvalidMessageTypeException: "invalid message type",
	WrongMethodName:             "wrong method name",
	BadSequenceID:               "bad sequence ID",
	MissingResult:               "missing result",
	InternalError:               "unknown internal error",
	ProtocolError:               "unknown protocol error",
	InvalidTransform:            "Invalid transform",
	InvalidProtocol:             "Invalid protocol",
	UnsupportedClientType:       "Unsupported client type",
	UnknownService:              "unknown service",
}

// TransError is the error that can be transmitted, it corresponds to TApplicationException in Thrift
type TransError struct {
	message string
	typeID  int32
	rawErr  error
}

// Error implements the error interface.

Review comment (suggestion):
the type id are corresponding with the definition in thrift TApplicationException, it's better to skip some numbers if add new typeid. can use 20 and add comment to describe it, the typeid from 20 are new defined typeid in Kitex

Code after:
 * limitations under the License.
 */

package remote

import (
	"errors"
	"fmt"

	"github.com/cloudwego/kitex/pkg/kerrors"
)

// corresponding with thrift TApplicationException, cannot change it
const (
	UnknownApplicationException = 0
	UnknownMethod               = 1
	InvalidMessageTypeException = 2
	WrongMethodName             = 3
	BadSequenceID               = 4
	MissingResult               = 5
	InternalError               = 6
	ProtocolError               = 7
	InvalidTransform            = 8
	InvalidProtocol             = 9
	UnsupportedClientType       = 10
	// kitex's own type id from number 20
	UnknownService = 20
)

var defaultTransErrorMessage = map[int32]string{
	UnknownApplicationException: "unknown application exception",
	UnknownMethod:               "unknown method",
	InvalidMessageTypeException: "invalid message type",
	WrongMethodName:             "wrong method name",
	BadSequenceID:               "bad sequence ID",
	MissingResult:               "missing result",
	InternalError:               "unknown internal error",
	ProtocolError:               "unknown protocol error",
	InvalidTransform:            "Invalid transform",
	InvalidProtocol:             "Invalid protocol",
	UnsupportedClientType:       "Unsupported client type",
	UnknownService:              "unknown service",
}

// TransError is the error that can be transmitted, it corresponds to TApplicationException in Thrift
type TransError struct {
	message string
	typeID  int32
	rawErr  error
}