Skip to content

Commit

Permalink
protosanitizer: fix panic if enum value is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Jan 4, 2025
1 parent d002ca2 commit 13f8e9b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion protosanitizer/protosanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func stripSingleValue(field protoreflect.FieldDescriptor, v protoreflect.Value)
case protoreflect.MessageKind:
return stripMessage(v.Message())
case protoreflect.EnumKind:
return field.Enum().Values().ByNumber(v.Enum()).Name()
desc := field.Enum().Values().ByNumber(v.Enum())
if desc == nil {
return v.Enum()
}
return desc.Name()
default:
return v.Interface()
}
Expand Down

0 comments on commit 13f8e9b

Please sign in to comment.