Skip to content

Provide better diagnostics when a descriptor is missing a property required by the snippet template #678

Open
@FloHin

Description

@FloHin

Background: I removed some method calls to "description()" to better debug my Rest tests, big mistake.

Now I understand the exception, but I needed to debug it, to understand that not the "description" of my entity was meant, but that "FieldDescriptor for path '$my_variable_name' has no description"

UseCase: As a developer, I want the exception to show me what field exactly is meant.

I understand that this is not a "bug report", but merely a minor proposal to improve "developer happiness", as it took me really a long time to figure out what was wrong

Reproduce:

Instead of

...
fieldWithPath(prefix + "input_data_type").type(JsonFieldType.STRING).description("DataType for input data")
...

forget the description

...
fieldWithPath(prefix + "input_data_type").type(JsonFieldType.STRING)
...

Exception:

No key, method or field with name 'description' on line 7
org.springframework.restdocs.mustache.MustacheException$Context: No key, method or field with name 'description' on line 7
	at org.springframework.restdocs.mustache.Mustache$VariableSegment.execute(Mustache.java:789)
	at org.springframework.restdocs.mustache.Template$1.execute(Template.java:131)
	at org.springframework.restdocs.mustache.Template$1.execute(Template.java:124)
	at org.springframework.restdocs.mustache.Template$Fragment.execute(Template.java:59)
	at org.springframework.restdocs.templates.mustache.AsciidoctorTableCellContentLambda.execute(AsciidoctorTableCellContentLambda.java:36)
	at org.springframework.restdocs.mustache.Mustache$SectionSegment.execute(Mustache.java:856)
	at org.springframework.restdocs.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:827)
	at org.springframework.restdocs.mustache.Mustache$SectionSegment.execute(Mustache.java:848)
	at org.springframework.restdocs.mustache.Template.executeSegs(Template.java:114)
	at org.springframework.restdocs.mustache.Template.execute(Template.java:91)
	at org.springframework.restdocs.mustache.Template.execute(Template.java:82)
	at org.springframework.restdocs.templates.mustache.MustacheTemplate.render(MustacheTemplate.java:62)
	at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:82)
	at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:191)
	at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:52)
	at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:201)
	at com.mlreef.rest.api.DataProcessorApiTest.Can retrieve all DataProcessors filtered(DataProcessorApiTest.kt:110)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementEnhancement that adds a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions