Skip to content
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

Merged
merged 3 commits into from
May 24, 2022

Conversation

zaquestion
Copy link
Contributor

@zaquestion zaquestion commented May 18, 2022

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

        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.IsValid 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.

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.
@sourcelevel-bot
Copy link

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.

@zaquestion
Copy link
Contributor Author

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.

@zaquestion
Copy link
Contributor Author

@imdario Just poking you again as a reminder to peek at this. Hope ya had a lovely weekend

@darccio darccio self-assigned this May 23, 2022
@darccio
Copy link
Owner

darccio commented May 24, 2022

@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.

@darccio darccio merged commit fd7d2bc into darccio:master May 24, 2022
kodiakhq bot referenced this pull request in cloudquery/cloudquery Feb 1, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/imdario/mergo](https://github.com/imdario/mergo) | indirect | patch | `v0.3.12` -> `v0.3.13` |

---

### Release Notes

<details>
<summary>imdario/mergo</summary>

### [`v0.3.13`](https://github.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://github.com/imdario/mergo/compare/v0.3.12...v0.3.13)

#### What's Changed

-   Fix typo in README.md by [@&#8203;eltociear](https://github.com/eltociear) in [https://github.com/imdario/mergo/pull/184](https://github.com/imdario/mergo/pull/184)
-   Adding StructBot to Mergo in the wild section by [@&#8203;tjpnz](https://github.com/tjpnz) in [https://github.com/imdario/mergo/pull/193](https://github.com/imdario/mergo/pull/193)
-   Add Goreleaser to featured projects by [@&#8203;marcauberer](https://github.com/marcauberer) in [https://github.com/imdario/mergo/pull/191](https://github.com/imdario/mergo/pull/191)
-   fix: gate transformers on valid non-nil destinations by [@&#8203;zaquestion](https://github.com/zaquestion) in [https://github.com/imdario/mergo/pull/211](https://github.com/imdario/mergo/pull/211)
-   Support slices of same type by [@&#8203;heaths](https://github.com/heaths) in [https://github.com/imdario/mergo/pull/210](https://github.com/imdario/mergo/pull/210)
-   Upgrade yaml to v3 by [@&#8203;imdario](https://github.com/imdario) in [https://github.com/imdario/mergo/pull/212](https://github.com/imdario/mergo/pull/212)

#### New Contributors

-   [@&#8203;eltociear](https://github.com/eltociear) made their first contribution in [https://github.com/imdario/mergo/pull/184](https://github.com/imdario/mergo/pull/184)
-   [@&#8203;tjpnz](https://github.com/tjpnz) made their first contribution in [https://github.com/imdario/mergo/pull/193](https://github.com/imdario/mergo/pull/193)
-   [@&#8203;marcauberer](https://github.com/marcauberer) made their first contribution in [https://github.com/imdario/mergo/pull/191](https://github.com/imdario/mergo/pull/191)
-   [@&#8203;zaquestion](https://github.com/zaquestion) made their first contribution in [https://github.com/imdario/mergo/pull/211](https://github.com/imdario/mergo/pull/211)
-   [@&#8203;heaths](https://github.com/heaths) made their first contribution in [https://github.com/imdario/mergo/pull/210](https://github.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://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDkuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEwOS4xIn0=-->
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