-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
fix: gate transformers on valid non-nil destinations #211
fix: gate transformers on valid non-nil destinations #211
Conversation
This builds on darccio#203 which attempted to provide a more flexible gating to running transformers. However upon testing darccio#203 in my own environment, I ran into the first panic listed below. There are a variety of errors that can happen when trying to run reflection on zero values: 2 just from my testing of this PR ``` panic: reflect: call of reflect.Value.Type on zero Value panic: reflect: call of reflect.Value.FieldByName on zero Value ``` The panic specifically calls out zero values, but it's actual a more specific set of values which is covered by `reflect.IsValid`. I attempted to replace the check with `reflect.IsZero`, which ends up being too restrictive and breaks existing tests. I also attempted to solely use `reflect.IsZero` which is not restrictive enough and cause the later panic above in the tests. Thus I arrived on the combination in this PR which seems to strike the "right" balance.
Hello, @zaquestion! This is your first Pull Request that will be reviewed by SourceLevel, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information. |
Added a test for the specific panic I alluded to in #203, I had significant trouble reproducing the case my integration tests were hitting so I ultimately settled for adding the test in the way I did as I didn't want it to be left entirely uncovered. |
@imdario Just poking you again as a reminder to peek at this. Hope ya had a lovely weekend |
@zaquestion It wasn't as pleasant as I expected. Sorry for the delay. It looks good, all tests are green and the code feels quite right. |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/imdario/mergo](https://togithub.com/imdario/mergo) | indirect | patch | `v0.3.12` -> `v0.3.13` | --- ### Release Notes <details> <summary>imdario/mergo</summary> ### [`v0.3.13`](https://togithub.com/imdario/mergo/releases/tag/v0.3.13): Merging same-type slices supported, YAML upgraded to v3 (only used in tests), and more flexibility for transformers [Compare Source](https://togithub.com/imdario/mergo/compare/v0.3.12...v0.3.13) #### What's Changed - Fix typo in README.md by [@​eltociear](https://togithub.com/eltociear) in [https://github.com/imdario/mergo/pull/184](https://togithub.com/imdario/mergo/pull/184) - Adding StructBot to Mergo in the wild section by [@​tjpnz](https://togithub.com/tjpnz) in [https://github.com/imdario/mergo/pull/193](https://togithub.com/imdario/mergo/pull/193) - Add Goreleaser to featured projects by [@​marcauberer](https://togithub.com/marcauberer) in [https://github.com/imdario/mergo/pull/191](https://togithub.com/imdario/mergo/pull/191) - fix: gate transformers on valid non-nil destinations by [@​zaquestion](https://togithub.com/zaquestion) in [https://github.com/imdario/mergo/pull/211](https://togithub.com/imdario/mergo/pull/211) - Support slices of same type by [@​heaths](https://togithub.com/heaths) in [https://github.com/imdario/mergo/pull/210](https://togithub.com/imdario/mergo/pull/210) - Upgrade yaml to v3 by [@​imdario](https://togithub.com/imdario) in [https://github.com/imdario/mergo/pull/212](https://togithub.com/imdario/mergo/pull/212) #### New Contributors - [@​eltociear](https://togithub.com/eltociear) made their first contribution in [https://github.com/imdario/mergo/pull/184](https://togithub.com/imdario/mergo/pull/184) - [@​tjpnz](https://togithub.com/tjpnz) made their first contribution in [https://github.com/imdario/mergo/pull/193](https://togithub.com/imdario/mergo/pull/193) - [@​marcauberer](https://togithub.com/marcauberer) made their first contribution in [https://github.com/imdario/mergo/pull/191](https://togithub.com/imdario/mergo/pull/191) - [@​zaquestion](https://togithub.com/zaquestion) made their first contribution in [https://github.com/imdario/mergo/pull/211](https://togithub.com/imdario/mergo/pull/211) - [@​heaths](https://togithub.com/heaths) made their first contribution in [https://github.com/imdario/mergo/pull/210](https://togithub.com/imdario/mergo/pull/210) **Full Changelog**: darccio/mergo@0.3.12...v0.3.13 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 3am on the first day of the month" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDkuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEwOS4xIn0=-->
This builds on #203 which attempted to provide a more flexible gating to
running transformers. However upon testing #203 in my own environment, I
ran into the first panic listed below.
There are a variety of errors that can happen when trying to run
reflection on zero values:
2 just from my testing of this PR
The panic specifically calls out zero values, but it's actual a more
specific set of values which is covered by
reflect.IsValid
.I attempted to replace the check with
reflect.IsZero
, which ends upbeing too restrictive and breaks existing tests. I also attempted to
solely use
reflect.IsValid
which is not restrictive enough and causethe later panic above in the tests. Thus I arrived on the combination in
this PR which seems to strike the "right" balance.