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

Enclose missing Rust template parameters in backticks in the exception message #1492

Merged
merged 4 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ private fun transformTemplate(template: String, scope: Array<out Pair<String, An
val templateType = matchResult.groupValues[2].ifEmpty { ":T" }
if (!scope.toMap().keys.contains(keyName)) {
throw CodegenException(
"Rust block template expected `$keyName` but was not present in template.\n hint: Template contains: ${
scope.map { it.first }
}"
"""
Rust block template expected `$keyName` but was not present in template.
hint: Template contains: ${scope.map { "`${it.first}`" }}
""".trimIndent()
)
}
"#{${keyName.lowercase()}$templateType}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.SetShape
Expand Down Expand Up @@ -143,4 +145,21 @@ class RustWriterTest {
)
sut.toString().shouldContain("inner: hello, regular: http::foo")
}

@Test
fun `missing template parameters are enclosed in backticks in the exception message`() {
val sut = RustWriter.forModule("lib")
val exception = assertThrows<CodegenException> {
sut.rustTemplate(
"#{Foo} #{Bar}",
"Foo Bar" to CargoDependency.Http.asType().member("foo"),
"Baz" to CargoDependency.Http.asType().member("baz")
)
}
exception.message shouldBe
"""
Rust block template expected `Foo` but was not present in template.
hint: Template contains: [`Foo Bar`, `Baz`]
""".trimIndent()
}
}