Remora.Discord icon indicating copy to clipboard operation
Remora.Discord copied to clipboard

[Bug]: Getting an auto mod message results in ExceptionError

Open pititu opened this issue 1 year ago • 4 comments

Description

Calling IDiscordRestChannelAPI#GetChannelMessageAsync with a message id of an auto mod action such as: image returns a result whose Error is set to an ExceptionError.

The error:

ExceptionError 
{
	Message = Failed to deserialize an enumeration value., 
	Exception = System.Text.Json.JsonException: Failed to deserialize an enumeration value.
   at Remora.Rest.Json.StringEnumConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.Read[TValue](Utf8JsonReader& reader, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](Utf8JsonReader& reader, JsonSerializerOptions options)
   at Remora.Rest.Json.Internal.OptionalConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at Remora.Rest.Json.Internal.BoundDataObjectConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at Remora.Rest.Json.Internal.BoundDataObjectConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
   at Remora.Rest.RestHttpClient`1.UnpackResponseAsync[TEntity](HttpResponseMessage response, String jsonPath, Boolean allowNullReturn, CancellationToken ct)
   at Remora.Rest.RestHttpClient`1.UnpackResponseAsync[TEntity](HttpResponseMessage response, String jsonPath, Boolean allowNullReturn, CancellationToken ct)
   at Remora.Rest.RestHttpClient`1.GetAsync[TEntity](String endpoint, String jsonPath, Action`1 configureRequestBuilder, Boolean allowNullReturn, CancellationToken ct)
}

Steps to Reproduce

  1. Call IDiscordRestChannelAPI#GetChannelMessageAsync with message id of a Discord's auto mod action
  2. Inspect the returned Result's Error

Expected Behavior

The method to return a successful Result<IMessage> with a valid Entity.

Current Behavior

A Result<IMessage> with the Error property set to ExceptionError is returned.

Library / Runtime Information

Remora.Discord.API: 73.0.0-github4632897105 Remora.Discord.API.Abstractions: 77.0.0-github4632897105

pititu avatar Apr 11 '23 16:04 pititu

This is due to Automod using an undocumented embed type auto_moderation_message.

image

VelvetToroyashi avatar Apr 11 '23 16:04 VelvetToroyashi

Could one of you open an issue on the docs repo for that type?

Nihlus avatar May 01 '23 18:05 Nihlus

They have no intentions on documenting this, as AutoMod is "in beta and still being finalized" if memory serves.

VelvetToroyashi avatar May 01 '23 18:05 VelvetToroyashi

That and embed types being deprecated, as far as the documentation is concerned.

VelvetToroyashi avatar May 01 '23 18:05 VelvetToroyashi