故障排查
本页介绍使用 Fory JavaScript 时常见的问题。
无法反序列化非跨语言载荷
Fory JavaScript 运行时只能读取 Fory 的跨语言载荷。如果生产端是 Java 或 Go 服务,并且使用的是语言原生格式,那么 JavaScript 侧无法解码。
修复方式:把生产端切换到跨语言模式。Java 请使用 .withLanguage(Language.XLANG),Go 请使用 WithXlang(true)。
maxDepth must be an integer >= 2
这表示你传入了无效的 maxDepth 值。它必须是大于等于 2 的正整数。
new Fory({ maxDepth: 100 });
只有当你的数据确实存在很深的嵌套时,才应提高这个值。
Binary size ... exceeds maxBinarySize
某个二进制字段或整条消息超过了安全限制。如果这个大小符合预期,且数据源可信,可以提高限制:
new Fory({ maxBinarySize: 128 * 1024 * 1024 });
Collection size ... exceeds maxCollectionSize
某个 list、set 或 map 的元素数量超过了配置上限。这通常意味着数据异常地大。如果这是合法场景,可以提高限制:
new Fory({ maxCollectionSize: 2_000_000 });
Field "..." is not nullable
你向一个未声明为可空的字段传入了 null。修复方式:在字段 schema 上添加 .setNullable(true):
const userType = Type.struct("example.user", {
name: Type.string(),
email: Type.string().setNullable(true), // ← this field can be null
});