-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Throw all configuration errors together #4525
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
Throw all configuration errors together #4525
Conversation
Previously, if the configuration contained bad type maps, `AssertConfigurationIsValid` would throw immediately without performing a dry run. Now, type map errors are thrown alongside any dry run errors. #4524
lbargaoanu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But my point is, why throw and catch? We can simply gather the errors instead.
| public void AssertConfigurationIsValid(IGlobalConfiguration config, TypeMap[] typeMaps) | ||
| { | ||
| List<Exception> configExceptions = []; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove all the empty lines.
Hi @lbargaoanu, I certainly could change the error collection to remove the throw/catch/throw - I'd like to discuss the approach first if that's ok with you. With private IEnumerable<AutoMapperConfigurationException> DryRunTypeMap(...)or, since the exceptions are always constructed directly from the , it could be this: private IEnumerable<MemberMap> DryRunTypeMap(...)I feel that returning exceptions (option 1) is not idiomatic .NET, while option 2 makes it harder to indicate that the output of the dry run is the set of failed member maps. It could perhaps be renamed to |
|
I think we can simply use the existing exceptions list. But |
…le` flow Previously the validator would call exception-throwing methods, catch and collect the exceptions, then rethrow them. The new logic collects the set of invalid member maps and generates the exceptions just before throwing them. This simplifies the logic and keeps exception creation in one place.
|
@lbargaoanu agreed, it should be fine. I have a cleaner version working and will push it within the week once I've finished tidying it. |
|
Hi @lbargaoanu, I've pushed a refactor where the exceptions are all created at the top layer, from the set of invalid maps. I've also done some renaming, flattened out some of the recursion to make it (to my eye) easier to understand and made the local function change you suggested in order to reduce the number of parameters. It would probably be cleaner if I turned the struct back into a class and replaced the I also need to add another test, as the replacement of the throws with yields means the validation will go deeper and surface more mapping errors upfront. I'll do that next week. Please tell me what you think, as I'm aware I have made some opinionated changes. |
|
I'm sorry, but I think this went in the wrong direction. I've opened a PR with minimal changes. |
|
@lbargaoanu, I think we may just have different philosophies, but perhaps "went in the wrong direction" is more about me not being entirely clear about the reason for the changes:
|
|
We kind of need a good reason to rewrite working code and I just don't see it here. Minor improvements should mean minor changes. |
I find this ironic, as that's what I felt I was doing when I first opened this PR. I just moved the exception collection upward one block and added a test (e364d54). Your response to that was this:
i.e. to rewrite working code. I took this as a request from you to refactor what is, to me, a very complex piece of code, which of course led us to this point, where it turns out that isn't what you wanted. I feel that what you've done in #4526 is on the same level of change as what I've done - you've changed the validator instantiation model, you've changed a struct to a class, started collecting exceptions etc. Anyway, of course I have no expectation of getting any of my changes into the project, I just feel we have not been able to communicate clearly with one another throughout this process, and it's been very disappointing. |
|
Sorry about that. But if you look again, hopefully you'll see how my PR is a bunch of trivial changes, as opposed to what you've done here. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. |
Previously, if the configuration contained bad type maps,
AssertConfigurationIsValidwould throw immediately without performing a dry run. Now, type map errors are thrown alongside any dry run errors.#4524