go data_error ai_generated true

rpc 错误:代码 = Internal 描述 = grpc:编组时出错:字符串字段包含无效的 UTF-8

rpc error: code = Internal desc = grpc: error while marshaling: string field contains invalid UTF-8

ID: go/grpc-invalid-header

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-11-11首次发现

版本兼容性

版本状态引入弃用备注
1.11 active

根因分析

proto 消息中的字符串字段包含无效的 UTF-8 字节,违反了 proto3 字符串要求。

English

A string field in the proto message contains invalid UTF-8 bytes, which violates proto3 string requirements.

generic

解决方案

  1. 90% 成功率
    req.Name = strings.ToValidUTF8(req.Name, "")
  2. 50% 成功率
    marshaler := protojson.MarshalOptions{EmitUnpopulated: true}; data, _ := marshaler.Marshal(msg)

无效尝试

常见但无效的做法:

  1. 60% 失败

    Changing field type requires proto regeneration and may break compatibility.

  2. 100% 失败

    The marshaling will fail and the RPC will not complete.