Skip to content
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

Unsigned Long handling in GatewayDiscordClient#getMessageById #1119

Open
Techtony96 opened this issue Feb 23, 2023 · 7 comments · Fixed by #1129
Open

Unsigned Long handling in GatewayDiscordClient#getMessageById #1119

Techtony96 opened this issue Feb 23, 2023 · 7 comments · Fixed by #1129
Labels
bug A general bug
Milestone

Comments

@Techtony96
Copy link
Contributor

Techtony96 commented Feb 23, 2023

To Reproduce:

GatewayDiscordClient.getMessageById(Snowflake.of("10781908199467992071"), Snowflake.of("10781908199467992071"));

Expected Behavior:
A 404 (because the message/channel are fake IDs) but a request made with the correct IDs

/channels/10781908199467992071/messages/10781908199467992071

Actual Behavior:

discord4j.rest.http.client.ClientException: GET /channels/-7664835874241559545/messages/-7664835874241559545 returned 400 Bad Request with response {code=50035, message=Invalid Form Body, errors={message_id={_errors=[{code=NUMBER_TYPE_MIN, message=snowflake value should be greater than or equal to 0.}]}}}

Version:
3.2.3

Other:

@Doc94
Copy link
Member

Doc94 commented Feb 25, 2023

I check this... but the issue is not D4J, you are sending an invalid snowflake then discord return a error in parsing, if you change the ID to like (channel: 727606882604154970) (message: 91776136072360350) you get the 404 because the snowflakes are valid but the API not found any related to this.

Image using ID mentioned in my message
image

Image using ID mentioned in issue
image

Note: maybe for the D4J side can be added a validation to Snowflate to not allow values great than the permit by discord, but the error returning by discord is valid.

@Techtony96
Copy link
Contributor Author

Techtony96 commented Mar 4, 2023

@Doc94 How is my snowflake invalid? According to the Discord docs "Snowflake IDs are up to 64 bits in size" which is a max value of 18446744073709551616. My value is 10781908199467992071. (which is within the 2^64 limit)

https://discord.com/developers/docs/reference#snowflakes

@Doc94
Copy link
Member

Doc94 commented Mar 4, 2023

@Doc94 How is my snowflake invalid? According to the Discord docs "Snowflake IDs are up to 64 bits in size" which is a max value of 18446744073709551616. My value is 10781908199467992071. (which is within the 2^64 limit)

https://discord.com/developers/docs/reference#snowflakes

yeah but the response of discord say the max value is 9223372036854775807, that with the REST in postman then maybe the issue is the docs in discord... my message was directly was discord say, then D4J cannot change this.

@darichey
Copy link
Member

darichey commented Mar 4, 2023

GET /channels/-7664835874241559545/

we shouldn't be making a request with this ID regardless of how discord will respond. We're probably accidentally using Snowflake#asLong instead of asString somewhere.

@Doc94
Copy link
Member

Doc94 commented Mar 4, 2023

GET /channels/-7664835874241559545/

we shouldn't be making a request with this ID regardless of how discord will respond. We're probably accidentally using Snowflake#asLong instead of asString somewhere.

yeah but this still not change the thing about the large snow not? im sure is a issue in discord docs

@quanticc
Copy link
Member

quanticc commented Mar 4, 2023

we shouldn't be making a request with this ID regardless of how discord will respond. We're probably accidentally using Snowflake#asLong instead of asString somewhere.

I think our Store or at least Rest classes would need to use strings, or apply a conversion at the DiscordWebRequest/RouteUtils level

@quanticc quanticc added this to the 3.2.x Backlog milestone Mar 4, 2023
@quanticc quanticc added the bug A general bug label Mar 4, 2023
Gregory-Widmer added a commit to Gregory-Widmer/Discord4J that referenced this issue Apr 6, 2023
@Gregory-Widmer
Copy link
Contributor

Hello, I proposed a fix in #1129. When trying to ue the provided Snowflakes, we now have the correct formatting, even if Discord response is the same :

Exception in thread "main" discord4j.rest.http.client.ClientException: GET /channels/10781908199467992071/messages/10781908199467992071 returned 400 Bad Request with response {code=50035, message=Invalid Form Body, errors={channel_id={_errors=[{code=NUMBER_TYPE_MAX, message=snowflake value should be less than or equal to 9223372036854775807.}]}, message_id={_errors=[{code=NUMBER_TYPE_MAX, message=snowflake value should be less than or equal to 9223372036854775807.}]}}}
	at discord4j.rest.http.client.ClientResponse.clientException(ClientResponse.java:171)
	Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ Request to GET /channels/10781908199467992071/messages/10781908199467992071 [RequestStream]
	*__checkpoint ⇢ Request to GET /channels/10781908199467992071/messages/10781908199467992071 [DefaultRouter]
Original Stack Trace:
		at discord4j.rest.http.client.ClientResponse.clientException(ClientResponse.java:171)
		at discord4j.rest.http.client.ClientResponse.lambda$createException$13(ClientResponse.java:149)
		at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125)
		at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839)
		at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249)
		at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122)
		at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:126)
		at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854)
		at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854)
		at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854)
		at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:224)
		at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onNext(FluxDoFinally.java:113)
		at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:191)
		at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107)
		at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839)
		at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:129)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260)
		at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144)
		at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:415)
		at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:424)
		at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:478)
		at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:712)

Azn9 added a commit that referenced this issue Apr 2, 2024
* fix(long): fix unsigned long printing in requests (#1119)

* fix: revert format change

---------

Co-authored-by: Axel Joly <azn9.pro@gmail.com>
Azn9 added a commit to Azn9/Discord4J that referenced this issue Apr 2, 2024
* fix(long): fix unsigned long printing in requests (Discord4J#1119)

* fix: revert format change

---------

Co-authored-by: Axel Joly <azn9.pro@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

5 participants