Skip to content

Provide destinationPath in error messages for Mapping, Convert, Set, Instantiate#444

Open
eryabitskiy wants to merge 1 commit into
modelmapper:masterfrom
eryabitskiy:master
Open

Provide destinationPath in error messages for Mapping, Convert, Set, Instantiate#444
eryabitskiy wants to merge 1 commit into
modelmapper:masterfrom
eryabitskiy:master

Conversation

@eryabitskiy
Copy link
Copy Markdown

@eryabitskiy eryabitskiy commented Feb 10, 2019

Provide destinationPath in error messages for Mapping, Convert, Set, Instantiate.

Current error messages lack of debug information and not informative enough.
If I have multiple properties, I have no idea which property failed and what it's name.
This changes should fix it.

For example:

org.modelmapper.MappingException: ModelMapper mapping errors:

1) Failed to instantiate instance of destination java.util.List. Ensure that java.util.List has a non-private no-argument constructor.

1 error

	at org.modelmapper.internal.Errors.throwMappingExceptionIfErrorsExist(Errors.java:380)
	at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:80)
	at org.modelmapper.ModelMapper.mapInternal(ModelMapper.java:573)
	at org.modelmapper.ModelMapper.map(ModelMapper.java:406)
Caused by: java.lang.NoSuchMethodException: java.util.List.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.getDeclaredConstructor(Class.java:2178)
	at org.modelmapper.internal.MappingEngineImpl.instantiate(MappingEngineImpl.java:332)
	at org.modelmapper.internal.MappingEngineImpl.createDestination(MappingEngineImpl.java:347)
	at org.modelmapper.internal.MappingEngineImpl.typeMap(MappingEngineImpl.java:140)
	at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:114)
	at org.modelmapper.internal.MappingEngineImpl.setDestinationValue(MappingEngineImpl.java:241)
	at org.modelmapper.internal.MappingEngineImpl.propertyMap(MappingEngineImpl.java:187)
	at org.modelmapper.internal.MappingEngineImpl.typeMap(MappingEngineImpl.java:151)
	at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:105)
	at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:71)
	... 43 more

@chhsiao90
Copy link
Copy Markdown
Member

Hi @eryabitskiy , Thanks for your pull request. I will take a look.

@chhsiao90 chhsiao90 self-requested a review February 13, 2020 00:58
@chhsiao90
Copy link
Copy Markdown
Member

It's a good idea to have more information in the error message, so we can do the troubleshooting quickly. But it's not ideal to add 'destinationPath' new argument to some methods for just improving the error message. It introduces lots of complexity.

I guessed we can have different approach to have the 'destinationPath' information in the error message without adding new argument.

Thanks for you pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants