| title | sidebar_position | id | license |
|---|---|---|---|
Troubleshooting |
10 |
troubleshooting |
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
|
This page covers common issues and debugging techniques for Apache Fory™ Rust.
Error: TypeId ... not found in type_info registry
Cause: The type was never registered with the current Fory instance.
Solution: Register the type before serialization:
let mut fory = Fory::default();
fory.register::<MyStruct>(100)?; // Register before useConfirm that:
- Every serializable struct or trait implementation calls
fory.register::<T>(type_id) - The same IDs are reused on the deserialize side
Cause: Field types are incompatible or schema has changed.
Solution:
- Enable compatible mode for schema evolution
- Ensure field types match across versions
let fory = Fory::default().compatible(true);Toggle FORY_PANIC_ON_ERROR=1 alongside RUST_BACKTRACE=1 to panic at the exact site an error is constructed:
RUST_BACKTRACE=1 FORY_PANIC_ON_ERROR=1 cargo test --features testsReset the variable afterwards to avoid aborting user-facing code paths.
Add the #[fory(debug)] attribute alongside #[derive(ForyObject)] to emit hook invocations:
#[derive(ForyObject)]
#[fory(debug)]
struct MyStruct {
field1: i32,
field2: String,
}Once compiled with debug hooks, call these functions to plug in custom callbacks:
set_before_write_field_funcset_after_write_field_funcset_before_read_field_funcset_after_read_field_func
Use reset_struct_debug_hooks() when you want the defaults back.
Without custom hooks, enable ENABLE_FORY_DEBUG_OUTPUT=1 to print field-level read/write events:
ENABLE_FORY_DEBUG_OUTPUT=1 cargo test --features testsThis is especially useful when investigating alignment or cursor mismatches.
Use cargo expand to inspect code generated by Fory derive macros:
cargo expand --test mod $mod$::$file$ > expanded.rscargo test --features testscargo test -p tests --test $test_file $test_methodRUST_BACKTRACE=1 FORY_PANIC_ON_ERROR=1 ENABLE_FORY_DEBUG_OUTPUT=1 \
cargo test --test mod $dir$::$test_file::$test_method -- --nocaptureSome integration tests expect FORY_PANIC_ON_ERROR to remain unset. Export it only for focused debugging sessions:
# For specific debugging only
FORY_PANIC_ON_ERROR=1 cargo test -p tests --test specific_test -- --nocapture
# Normal test run (without panic on error)
cargo test --features testsPrefer the static constructors on fory_core::error::Error:
Error::type_mismatchError::invalid_dataError::unknown
This keeps diagnostics consistent and makes opt-in panics work correctly.
| Environment Variable | Purpose |
|---|---|
RUST_BACKTRACE=1 |
Enable stack traces |
FORY_PANIC_ON_ERROR=1 |
Panic at error site for debugging |
ENABLE_FORY_DEBUG_OUTPUT=1 |
Print field-level read/write events |
- Configuration - Fory options
- Type Registration - Registration best practices
- Schema Evolution - Compatible mode