question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NRE in DiscordApiClient due to insufficient null handling

See original GitHub issue

Summary

Clearing a DiscordMessageBuilder of Components without adding any stickers to it causes an NRE when trying to send it via a DiscordRestClient (probably also normally, have only tested with a rest client)

Details

I have encountered it in every version since presumably the commit a1e5becd2dbd4bfdd37caa82116b1596b389a6e3. The issue is that invoking ClearComponents sets the Sticker to default here https://github.com/DSharpPlus/DSharpPlus/blob/94717715ce97651187c32655ae70f298801c12c8/DSharpPlus/Entities/Channel/Message/DiscordMessageBuilder.cs#L229-L236 But then when trying to send the Message in DiscordApiClient it is not handled when the sticker itself should be null https://github.com/DSharpPlus/DSharpPlus/blob/94717715ce97651187c32655ae70f298801c12c8/DSharpPlus/Net/Rest/DiscordApiClient.cs#L1358-L1367

Obviously this then also causes the message to fail to send.

This code snippet should be enough to reproduce the issue

var bot = new DiscordRestClient(...);
var messageBuilder = new DiscordMessageBuilder();
messageBuilder.WithContent("Test");
messageBuilder.ClearComponents();

await bot.CreateMessageAsync(<channel_id>, messageBuilder);

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
akiraveliaracommented, Feb 18, 2023

yes, v5 will use nullability annotations

0reactions
Izumemoricommented, Mar 2, 2023

#1481 Has fixed this, thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should one check for null if he does not expect null?
The method could check for null and abort the processing of users (which due to a bug is null) but return the "comments"...
Read more >
Solved: Expression.Error: We cannot convert the value null...
Everything were fine until yesterday when I started to get error Expression.Error: We cannot convert the value null to type Number from several...
Read more >
Null values creating new errors in edit query conditionals
Hi all, I have an employee data report where I have added a number of conditional statements to determine things like which employees...
Read more >
Getting errors with null fields - Power Automate
If you aren't handling null fields correctly, you may be expecting runtime errors like: InvalidTemplate. Unable to process template language ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found