danger/kotlin

Field 'approvals_before_merge' is required, but it was missing

davidbilik opened this issue · 3 comments

Hey guys, we've update to the newest version in the repository (we build binary from source) and this crash started to happen for us. Maybe we have older/newer gitlab version and this is not in the api but it should probably still not be required I suppose.

kotlinx.serialization.MissingFieldException: Field 'approvals_before_merge' is required, but it was missing
	at systems.danger.kotlin.GitLabMergeRequest.<init>(GitLab.kt:39)
	at systems.danger.kotlin.GitLabMergeRequest$$serializer.deserialize(GitLab.kt)
	at systems.danger.kotlin.GitLabMergeRequest$$serializer.deserialize(GitLab.kt:35)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:33)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:41)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:63)
	at systems.danger.kotlin.GitLab$$serializer.deserialize(GitLab.kt)
	at systems.danger.kotlin.GitLab$$serializer.deserialize(GitLab.kt:12)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:33)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:41)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:72)
	at systems.danger.kotlin.DangerDSL$$serializer.deserialize(DangerDSL.kt)
	at systems.danger.kotlin.DangerDSL$$serializer.deserialize(DangerDSL.kt:11)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:33)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:41)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:63)
	at systems.danger.kotlin.DSL$$serializer.deserialize(DangerDSL.kt)
	at systems.danger.kotlin.DSL$$serializer.deserialize(DangerDSL.kt:6)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:33)
	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:85)
	at systems.danger.kotlin.DangerRunner.<init>(DangerRunner.kt:232)
	at systems.danger.kotlin.DangerRunnerKt.Danger(DangerRunner.kt:198)
	at Dangerfile_df.<init>(Dangerfile.df.kts:93)

I found in the repo that the field is actually nullable but it seems that the change from moshi to kotlin serialization made it crashing now. According to this so question you need to define default value if the field is not in the json

well, considering that we probably need to set a default to 0