8000 [Notifier] Check Discord embed limitations by alamirault · Pull Request #47859 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] Check Discord embed limitations #47859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

alamirault
Copy link
Contributor
@alamirault alamirault commented Oct 13, 2022
Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #47688
License MIT
Doc PR symfony/symfony-docs#...

Add missing check on Discord Embeds (length and number).

See #47688 for description

Official embed limits: https://discord.com/developers/docs/resources/channel#embed-object-embed-limits

(unrelated phpunit failure)

@carsonbot carsonbot added this to the 6.2 milestone Oct 13, 2022
@alamirault alamirault force-pushed the feature/47688-add-discord-exception-limits branch 3 times, most recently from 995c655 to fa4a60c Compare October 13, 2022 21:19
@javiereguiluz
Copy link
Member

@alamirault thanks for this contribution.

I said the following before and folks didn't think it was an issue, but let me tell you again in case we can reconsider this:

(1) I think it's a mistake to add Discord (or any other third-party) validation logic in Symfony code. The reason is that Discord can change these rules at any time, making Symfony code outdated. (e.g. in this PR we validate that 25 is the max number of fields passed ... what if tomorrow or next week Discord increases or decreases that number?)

(2) We should fix/report obvious errors (e.g. you pass a string where a boolean is required) but we should not try to over-validate things. For example, if today's Discord field limit is 25 and developer sends 50 fields, let Discord fail and pass the API error message to the developer.

@@ -111,6 +125,10 @@ public function author(DiscordAuthorEmbedObject $author): static
*/
public function addField(DiscordFieldEmbedObject $field): static
{
if (self::FIELDS_LIMIT === \count($this->options['fields'] ?? [])) {
throw new LengthException(sprintf('Maximum number of fields should not exceed %d.', self::FIELDS_LIMIT));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new LengthException(sprintf('Maximum number of fields should not exceed %d.', self::FIELDS_LIMIT));
throw new LengthException(sprintf('Maximum number of fields must not exceed %d.', self::FIELDS_LIMIT));

@fabpot
Copy link
Member
fabpot commented Oct 15, 2022

I agree with @javiereguiluz and I think we should instead make the error message better if possible (the current one is indeed not helpful: Handling "Unable to post the Discord message: "" (embeds: 0).. Notice the empty error message from the server, that's probably a bug in how we parse the response from Discord.

@alamirault
Copy link
Contributor Author

@javiereguiluz I understand, it's logic !

However, what do you think about adding a warning that checks are not all covered by Symfony on component's README ? And add link to official API docs ?

@fabpot
Copy link
Member
fabpot commented Oct 15, 2022

I don't think there is a need for additional docs or links; the error messages coming from the API should be enough.

@fabpot
Copy link
Member
fabpot commented Oct 22, 2022

Thank you @alamirault.

@fabpot fabpot merged commit c2d3dd8 into symfony:6.2 Oct 22, 2022
@ToshY
Copy link
Contributor
ToshY commented Nov 14, 2022

I'm glad the issue got resolved one way or another, thanks @alamirault 👍

However, I'm still saddened that there's no useful documentation regarding these notifiers besides the generic documentation. I reckon adding just 1 complete example for each notifier in its own repo would already be a huge improvement, especially for those who have no idea how to customise the chat messages.

@OskarStark
Copy link
Contributor

I would appreciate a sub-section per notifier with some in-depth examples 👍

@alamirault alamirault deleted the feature/47688-add-discord-exception-limits branch November 14, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Notifier] [Discord] 400 HTTP response due to embed length
6 participants
0