# proto: 必填字段 "User.email" 未设置

- **ID:** `go/proto-required-field-not-set`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

proto2 的 required 字段在序列化前必须显式设置。proto3 没有 required 字段，因此该错误只出现在 proto2 或旧版生成代码中。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| github.com/golang/protobuf v1.5 / proto2 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   u.Email = proto.String("user@example.com")
if err := proto.Marshal(u); err != nil {
    log.Fatalf("marshal: %v", err)
}
   ```
2. **** (80% 成功率)
   ```
   // user.proto: syntax = "proto3";
// string email = 1 [ (validate.rules).string.email = true ];
   ```

## 无效尝试

- **** — Marshaling is deterministic; an unset required field stays unset. Retrying never fills the field. (95% 失败率)
- **** — Regenerating changes the API; callers relying on presence semantics may now send empty values silently. (50% 失败率)
