-
Notifications
You must be signed in to change notification settings - Fork 257
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
Detect deps that have already been invoked #346
Conversation
Detect when a dependency was accidentally already invoked mg.Deps(MyDep()) Normally this causes a nil pointer panic when we invoke the function Error: runtime error: invalid memory address or nil pointer dereference Now it will print the following as soon as its detected Error: A dependency of the current target was defined improperly, with parenthesis. Dependencies should be defined as mg.Deps(MyDep), not mg.Deps(MyDep()) I have applied this change to checkfn so that it applies to serial and parallel deps. Signed-off-by: Carolyn Van Slyck <[email protected]>
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.
LGTM. my only comment probably doesn't need to be addressed in this PR (at least IMO)
I ran into this today, thinking it was an issue with my logging.
I'd like to see this merge get moved forward to support better error output. |
@natefinch Let me know if you'd prefer to see this fixed in another way. I'm happy to change it up if needed. |
I think this is good but I think the error message needs to change a bit. It could be confusing if you pass in just a nil value of some sort. I think something more like |
The new mg.F function is the root of the nil-pointer error that can happen when someone accidentally calls mg.Deps(TargetA()). I have fixed the check for whether a function was passed so that it won't panic and included the usage for mg.F in the error message. I then added a similar check, is the target a function, to Deps/SerialDeps/CxtSerialDeps functions so that we can give a better error message when it's passed a non-function. The error message otherwise will reference mg.F which I don't think will help point people to the real problem, which is how they called mg.Deps/SerialDeps. Signed-off-by: Carolyn Van Slyck <[email protected]>
Thanks for the feedback! 🙇♀️ After merging with master, I took another look and found a better place to prevent the nil-pointer error. It can occur with mg.F and mg.Deps/SerialDeps. I incorporated your suggestion for the error message returned by mg.Deps. It doesn't assume that a nil must have come from an invoked function (though that's pretty common). Maybe they passed mg.Deps(3) instead and this will handle that better too.
When someone calls mg.F directly and passes in an invoked function, this is the error message:
|
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.
LGTM, thanks!
….0 (#6) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/magefile/mage](https://github.com/magefile/mage) | require | minor | `v1.11.0` -> `v1.14.0` | --- ### Release Notes <details> <summary>magefile/mage</summary> ### [`v1.14.0`](https://github.com/magefile/mage/releases/tag/v1.14.0): - Faster Than Ever [Compare Source](https://github.com/magefile/mage/compare/v1.13.0...v1.14.0) #### What's Changed - give props to netlify on the main page by [@​natefinch](https://github.com/natefinch) in [https://github.com/magefile/mage/pull/410](https://github.com/magefile/mage/pull/410) - Update site to build with newer hugo by [@​perrito666](https://github.com/perrito666) in [https://github.com/magefile/mage/pull/411](https://github.com/magefile/mage/pull/411) - bring docs for use of directives up to date by [@​efd6](https://github.com/efd6) in [https://github.com/magefile/mage/pull/407](https://github.com/magefile/mage/pull/407) - add blog post about v1.13 by [@​natefinch](https://github.com/natefinch) in [https://github.com/magefile/mage/pull/412](https://github.com/magefile/mage/pull/412) - fix author links by [@​natefinch](https://github.com/natefinch) in [https://github.com/magefile/mage/pull/413](https://github.com/magefile/mage/pull/413) - Add variadic support to mg.F by [@​perj](https://github.com/perj) in [https://github.com/magefile/mage/pull/402](https://github.com/magefile/mage/pull/402) - feat: rename templated imports to avoid collisions by [@​ladydascalie](https://github.com/ladydascalie) in [https://github.com/magefile/mage/pull/421](https://github.com/magefile/mage/pull/421) - Website: fixing typos by [@​deining](https://github.com/deining) in [https://github.com/magefile/mage/pull/429](https://github.com/magefile/mage/pull/429) - refactor(listGoFiles): remove go list dependency by [@​jaredallard](https://github.com/jaredallard) in [https://github.com/magefile/mage/pull/440](https://github.com/magefile/mage/pull/440) - doc: add MacPorts install info by [@​herbygillot](https://github.com/herbygillot) in [https://github.com/magefile/mage/pull/419](https://github.com/magefile/mage/pull/419) #### New Contributors - [@​efd6](https://github.com/efd6) made their first contribution in [https://github.com/magefile/mage/pull/407](https://github.com/magefile/mage/pull/407) - [@​perj](https://github.com/perj) made their first contribution in [https://github.com/magefile/mage/pull/402](https://github.com/magefile/mage/pull/402) - [@​ladydascalie](https://github.com/ladydascalie) made their first contribution in [https://github.com/magefile/mage/pull/421](https://github.com/magefile/mage/pull/421) - [@​deining](https://github.com/deining) made their first contribution in [https://github.com/magefile/mage/pull/429](https://github.com/magefile/mage/pull/429) - [@​jaredallard](https://github.com/jaredallard) made their first contribution in [https://github.com/magefile/mage/pull/440](https://github.com/magefile/mage/pull/440) - [@​herbygillot](https://github.com/herbygillot) made their first contribution in [https://github.com/magefile/mage/pull/419](https://github.com/magefile/mage/pull/419) **Full Changelog**: magefile/mage@v1.13.0...v1.14.0 ### [`v1.13.0`](https://github.com/magefile/mage/releases/tag/v1.13.0): - Magefiles Directory and more! [Compare Source](https://github.com/magefile/mage/compare/v1.12.1...v1.13.0) #### What's Changed - feat: allow mage:import alias to be defined for multiple imports by [@​viktorvoltaire](https://github.com/viktorvoltaire) in [https://github.com/magefile/mage/pull/398](https://github.com/magefile/mage/pull/398) - chore: wrap log.Println in cmd with verbose check by [@​viktorvoltaire](https://github.com/viktorvoltaire) in [https://github.com/magefile/mage/pull/399](https://github.com/magefile/mage/pull/399) - Detect deps that have already been invoked by [@​carolynvs](https://github.com/carolynvs) in [https://github.com/magefile/mage/pull/346](https://github.com/magefile/mage/pull/346) - Replace godoc.org URLs by [@​JamieEdge](https://github.com/JamieEdge) in [https://github.com/magefile/mage/pull/342](https://github.com/magefile/mage/pull/342) - Add magefiles directory support by [@​perrito666](https://github.com/perrito666) in [https://github.com/magefile/mage/pull/405](https://github.com/magefile/mage/pull/405) #### New Contributors - [@​viktorvoltaire](https://github.com/viktorvoltaire) made their first contribution in [https://github.com/magefile/mage/pull/398](https://github.com/magefile/mage/pull/398) - [@​carolynvs](https://github.com/carolynvs) made their first contribution in [https://github.com/magefile/mage/pull/346](https://github.com/magefile/mage/pull/346) - [@​JamieEdge](https://github.com/JamieEdge) made their first contribution in [https://github.com/magefile/mage/pull/342](https://github.com/magefile/mage/pull/342) - [@​perrito666](https://github.com/perrito666) made their first contribution in [https://github.com/magefile/mage/pull/405](https://github.com/magefile/mage/pull/405) **Full Changelog**: magefile/mage@v1.12.1...v1.13.0 ### [`v1.12.1`](https://github.com/magefile/mage/releases/tag/v1.12.1): - Second Verse, Same as the First [Compare Source](https://github.com/magefile/mage/compare/v1.12.0...v1.12.1) This is a copy of v1.12.0 ... nothing has changed. However, there was an initial v1.12.0 that was created accidentally, and then deleted, and it's causing some go proxies to complain. So hopefully this will fix that. #### Changelog - [`2f1ec40`](https://github.com/magefile/mage/commit/2f1ec40) ci: migrate from travis to github action ([#​391](https://github.com/magefile/mage/issues/391)) - [`fe9f942`](https://github.com/magefile/mage/commit/fe9f942) evidently goreleaseer has changed in the last 4 years :) ([#​394](https://github.com/magefile/mage/issues/394)) - [`fd5011e`](https://github.com/magefile/mage/commit/fd5011e) Fix the rollback mechanism for tags during a release ([#​392](https://github.com/magefile/mage/issues/392)) - [`404c119`](https://github.com/magefile/mage/commit/404c119) sh.run(): quoted strings before join ([#​306](https://github.com/magefile/mage/issues/306)) - [`0c5affe`](https://github.com/magefile/mage/commit/0c5affe) Add asdf installation instructions to docs ([#​383](https://github.com/magefile/mage/issues/383)) - [`e84bbc1`](https://github.com/magefile/mage/commit/e84bbc1) [#​288](https://github.com/magefile/mage/issues/288) add brew and scoop install to docs ([#​376](https://github.com/magefile/mage/issues/376)) - [`80953f7`](https://github.com/magefile/mage/commit/80953f7) [#​378](https://github.com/magefile/mage/issues/378) bump travisci go16 ([#​379](https://github.com/magefile/mage/issues/379)) - [`dd94424`](https://github.com/magefile/mage/commit/dd94424) Create issue templates ([#​374](https://github.com/magefile/mage/issues/374)) - [`d9e2e41`](https://github.com/magefile/mage/commit/d9e2e41) fix: deterministic compiled mainfile ([#​348](https://github.com/magefile/mage/issues/348)) - [`4cf3cfc`](https://github.com/magefile/mage/commit/4cf3cfc) make -h work with imported targets ([#​335](https://github.com/magefile/mage/issues/335)) - [`de7ca6c`](https://github.com/magefile/mage/commit/de7ca6c) fix test for go 1.16 ([#​330](https://github.com/magefile/mage/issues/330)) ### [`v1.12.0`](https://github.com/magefile/mage/releases/tag/v1.12.0): - Small Fixes [Compare Source](https://github.com/magefile/mage/compare/v1.11.0...v1.12.0) This is our first release in a while, and nothing major is added, but some small fixes have gone out, like making the mainfile deterministic and making sure we can use -h with imported targets. #### Changelog - [`2f1ec40`](https://github.com/magefile/mage/commit/2f1ec40) ci: migrate from travis to github action ([#​391](https://github.com/magefile/mage/issues/391)) - [`fe9f942`](https://github.com/magefile/mage/commit/fe9f942) evidently goreleaseer has changed in the last 4 years :) ([#​394](https://github.com/magefile/mage/issues/394)) - [`fd5011e`](https://github.com/magefile/mage/commit/fd5011e) Fix the rollback mechanism for tags during a release ([#​392](https://github.com/magefile/mage/issues/392)) - [`404c119`](https://github.com/magefile/mage/commit/404c119) sh.run(): quoted strings before join ([#​306](https://github.com/magefile/mage/issues/306)) - [`0c5affe`](https://github.com/magefile/mage/commit/0c5affe) Add asdf installation instructions to docs ([#​383](https://github.com/magefile/mage/issues/383)) - [`e84bbc1`](https://github.com/magefile/mage/commit/e84bbc1) [#​288](https://github.com/magefile/mage/issues/288) add brew and scoop install to docs ([#​376](https://github.com/magefile/mage/issues/376)) - [`80953f7`](https://github.com/magefile/mage/commit/80953f7) [#​378](https://github.com/magefile/mage/issues/378) bump travisci go16 ([#​379](https://github.com/magefile/mage/issues/379)) - [`dd94424`](https://github.com/magefile/mage/commit/dd94424) Create issue templates ([#​374](https://github.com/magefile/mage/issues/374)) - [`d9e2e41`](https://github.com/magefile/mage/commit/d9e2e41) fix: deterministic compiled mainfile ([#​348](https://github.com/magefile/mage/issues/348)) - [`4cf3cfc`](https://github.com/magefile/mage/commit/4cf3cfc) make -h work with imported targets ([#​335](https://github.com/magefile/mage/issues/335)) - [`de7ca6c`](https://github.com/magefile/mage/commit/de7ca6c) fix test for go 1.16 ([#​330](https://github.com/magefile/mage/issues/330)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, 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 [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/scottames/cmder). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41Ny4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTcuMCJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Detect when a dependency was accidentally already invoked
Normally this causes a nil pointer panic when we invoke the function
Now it will print the following as soon as its detected
I have applied this change to checkfn so that it applies to serial and parallel deps.
Fixes #332