Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions discord/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,27 @@ func (c *ContainerComponents) UnmarshalJSON(b []byte) error {
return err
}

*c = make([]ContainerComponent, len(jsons))
components := make([]ContainerComponent, 0, len(jsons))
Comment thread
ayn2op marked this conversation as resolved.
Outdated

for i, b := range jsons {
for _, b := range jsons {
p, err := ParseComponent(b)
if err != nil {
return err
}

cc, ok := p.(ContainerComponent)
if !ok {
// If it's an unknown component, skip it instead of failing
// This allows messages with new component types to still be loaded
if _, isUnknown := p.(*UnknownComponent); isUnknown {
continue
}
Comment on lines +274 to +278

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt that branch is effectively unreachable? since *UnknownComponent implements TopLevelComponent, it is unreachable (!ok != false):
https://github.com/diamondburned/arikawa/pull/497/changes#diff-962d7ae8c081b5ff9c6617afaaf818bdba4b6245bddb2484609030c2e00d4e42R274-R278

return fmt.Errorf("expected container, got %T", p)
}
(*c)[i] = cc
components = append(components, cc)
}

*c = components
return nil
}

Expand Down Expand Up @@ -315,6 +321,14 @@ func ParseComponent(b []byte) (Component, error) {
c = &StringSelectComponent{}
case TextInputComponentType:
c = &TextInputComponent{}
case UserSelectComponentType:
c = &UserSelectComponent{}
case RoleSelectComponentType:
c = &RoleSelectComponent{}
case MentionableSelectComponentType:
c = &MentionableSelectComponent{}
case ChannelSelectComponentType:
c = &ChannelSelectComponent{}
default:
c = &UnknownComponent{typ: t.Type}
}
Expand Down
Loading