From 54ad1ee666fb26dcd332a1d2dc6067da71a86117 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 29 Aug 2025 16:21:34 +0800 Subject: [PATCH 1/3] Improve exception message for missing type mapper --- .../MapperlyAutoObjectMappingProvider.cs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs index 80f959710d..b2c0d6275f 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectMapping; -using Volo.Abp.Reflection; namespace Volo.Abp.Mapperly; @@ -62,8 +61,7 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider return destination; } - throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper))} or" + - $" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper))} was found"); + throw GetNoMapperFoundException(); } public virtual TDestination Map(TSource source, TDestination destination) @@ -95,8 +93,34 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider return destination; } - throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper))} or" + - $" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper))} was found"); + throw GetNoMapperFoundException(); + } + + protected virtual AbpException GetNoMapperFoundException() + { + var newLine = Environment.NewLine; + var message = "No type mapper class was found for the given source and destination types." + + newLine + + newLine + + "Mapping types:" + + newLine + + $"{typeof(TSource).Name} -> {typeof(TDestination).Name}" + + newLine + + $"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" + + newLine + + newLine + + "Define a mapping class to resolve this issue:" + + newLine + + " - Use MapperBase for one-way mapping." + + newLine + + " - Use TwoWayMapperBase for two-way mapping." + + newLine + + newLine + + "See the Mapperly documentation for details:" + + newLine + + "https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"; + + return new AbpException(message); } protected virtual bool TryToMapCollection(TSource source, TDestination? destination, out TDestination collectionResult) From abbcea5a742f448832913737cfc470b378e92ce2 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 29 Aug 2025 16:41:42 +0800 Subject: [PATCH 2/3] Update exception message for missing type mapper --- .../Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs index 3f0773f0a1..26c8cf2284 100644 --- a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs @@ -106,9 +106,13 @@ public class AbpMapperlyModule_Basic_Tests : AbpIntegratedTest(() =>_objectMapper.Map(new MyEntity())); - exception.Message.ShouldBe("No " + - "Volo.Abp.Mapperly.IAbpMapperlyMapper or " + - "Volo.Abp.Mapperly.IAbpReverseMapperlyMapper" + - " was found"); + exception.Message.ShouldBe("No type mapper class was found for the given source and destination types.\n\n" + + "Mapping types:\n" + + "MyEntity -> MyClassDto\n" + + "Volo.Abp.Mapperly.SampleClasses.MyEntity -> Volo.Abp.Mapperly.MyClassDto\n\n" + + "Define a mapping class to resolve this issue:\n" + + " - Use MapperBase for one-way mapping.\n" + + " - Use TwoWayMapperBase for two-way mapping.\n\n" + + "See the Mapperly documentation for details:\nhttps://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"); } } From 3599fc454c0dba2aa0719043dee6deca0299226a Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 1 Sep 2025 18:11:56 +0800 Subject: [PATCH 3/3] Update exception message for missing object mapping --- .../Mapperly/MapperlyAutoObjectMappingProvider.cs | 12 ++++++------ .../Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs index b2c0d6275f..71b3661303 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -99,26 +99,26 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider protected virtual AbpException GetNoMapperFoundException() { var newLine = Environment.NewLine; - var message = "No type mapper class was found for the given source and destination types." + + var message = "No object mapping was found for the specified source and destination types." + newLine + newLine + - "Mapping types:" + + "Mapping attempted:" + newLine + $"{typeof(TSource).Name} -> {typeof(TDestination).Name}" + newLine + $"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" + newLine + newLine + - "Define a mapping class to resolve this issue:" + + "How to fix:" + + newLine + + "Define a mapping class for these types:" + newLine + " - Use MapperBase for one-way mapping." + newLine + " - Use TwoWayMapperBase for two-way mapping." + newLine + newLine + - "See the Mapperly documentation for details:" + - newLine + - "https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"; + "For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"; return new AbpException(message); } diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs index 26c8cf2284..b5987769be 100644 --- a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs @@ -106,13 +106,14 @@ public class AbpMapperlyModule_Basic_Tests : AbpIntegratedTest(() =>_objectMapper.Map(new MyEntity())); - exception.Message.ShouldBe("No type mapper class was found for the given source and destination types.\n\n" + - "Mapping types:\n" + + exception.Message.ShouldBe("No object mapping was found for the specified source and destination types.\n\n" + + "Mapping attempted:\n" + "MyEntity -> MyClassDto\n" + "Volo.Abp.Mapperly.SampleClasses.MyEntity -> Volo.Abp.Mapperly.MyClassDto\n\n" + - "Define a mapping class to resolve this issue:\n" + + "How to fix:\n" + + "Define a mapping class for these types:" + "\n" + " - Use MapperBase for one-way mapping.\n" + " - Use TwoWayMapperBase for two-way mapping.\n\n" + - "See the Mapperly documentation for details:\nhttps://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"); + "For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"); } }