Skip to content

Commit

Permalink
Improve error message when using ResultBackNavigator with unsupported…
Browse files Browse the repository at this point in the history
… type.
  • Loading branch information
raamcosta committed Oct 17, 2024
1 parent d7ef249 commit 90e9a8b
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal class InitialValidator(
?: throw IllegalDestinationsSetup(
"ResultRecipient second type argument must be a valid type with no '*' variance."
)
validateResultType(resultType)
validateResultType(resultType, parameter.type.toTypeCode())

val resultOriginQualifiedName = parameter.getFirstArgTypeQualifiedName()

Expand Down Expand Up @@ -260,6 +260,17 @@ internal class InitialValidator(
"Destination annotated Composables must have at most one ResultBackNavigator"
)
}

resultBackNavigatorParams.forEach { parameter ->
val resultType =
(parameter.type.typeArguments.firstOrNull() as? TypeArgument.Typed?)?.type
?: throw IllegalDestinationsSetup(
"Composable '${annotatedName}': " +
"ResultBackNavigator type argument must be a valid type with no type arguments."
)

validateResultType(resultType, parameter.type.toTypeCode())
}
}

private fun DestinationGeneratingParams.validateOpenResultRecipients() {
Expand All @@ -270,10 +281,11 @@ internal class InitialValidator(
val resultType =
(parameter.type.typeArguments.firstOrNull() as? TypeArgument.Typed?)?.type
?: throw IllegalDestinationsSetup(
"OpenResultRecipient type argument must be a valid type with no type arguments."
"Composable '${annotatedName}': " +
"OpenResultRecipient type argument must be a valid type with no type arguments."
)

validateResultType(resultType)
validateResultType(resultType, parameter.type.toTypeCode())
}
}

Expand Down Expand Up @@ -319,9 +331,9 @@ internal class InitialValidator(
return (firstTypeArg as? TypeArgument.Typed)?.type?.importable?.qualifiedName
}

private fun DestinationGeneratingParams.validateResultType(resultType: TypeInfo) {
private fun DestinationGeneratingParams.validateResultType(resultType: TypeInfo, argString: String) {
if (!resultType.isNavArgType()) {
throw IllegalDestinationsSetup("Composable $annotatedName, ${resultType.toTypeCode()}: Result types must be of a valid navigation argument type.")
throw IllegalDestinationsSetup("Composable '$annotatedName', $argString: Result types must be of a valid navigation argument type, but was '${resultType.toTypeCode()}'.")
}
}

Expand Down

0 comments on commit 90e9a8b

Please sign in to comment.