故障排查
本指南汇总了使用 Fory Go 时的常见问题与解决方案。
错误类型
Fory Go uses typed errors with specific error kinds:
type Error struct {
kind ErrorKind
message string
// Additional context fields
}
func (e Error) Kind() ErrorKind { return e.kind }
func (e Error) Error() string { return e.message }
错误种类
| Kind | Value | Description |
|---|---|---|
ErrKindOK | 0 | No error |
ErrKindBufferOutOfBound | 1 | Read/write beyond buffer bounds |
ErrKindTypeMismatch | 2 | Type ID mismatch |
ErrKindUnknownType | 3 | Unknown type encountered |
ErrKindSerializationFailed | 4 | General serialization failure |
ErrKindDeserializationFailed | 5 | General deserialization failure |
ErrKindMaxDepthExceeded | 6 | Recursion depth limit exceeded |
ErrKindNilPointer | 7 | Unexpected nil pointer |
ErrKindInvalidRefId | 8 | Invalid reference ID |
ErrKindHashMismatch | 9 | Struct hash mismatch |
ErrKindInvalidTag | 10 | Invalid fory struct tag |
常见错误与解决方案
ErrKindUnknownType
Error: unknown type encountered
Cause: Type not registered before serialization/deserialization.
Solution:
f := fory.New()
// Register type before use
f.RegisterStruct(User{}, 1)
// Now serialization works
data, _ := f.Serialize(&User{ID: 1})
ErrKindTypeMismatch
Error: type mismatch: expected X, got Y
Cause: Serialized data has different type than expected.
Solutions:
- Use correct target type:
// Wrong: Deserializing User into Order
var order Order
f.Deserialize(userData, &order) // Error!
// Correct
var user User
f.Deserialize(userData, &user)