-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 incorrectTypeForFlagError
for unknowns
#1708
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why don't we just do: fmt.Errorf("Mismatched type for flag '%s'. Expected '%s' but actual is '%T'", name, expectedTypeName, value) func TestXxx(t *testing.T) {
var value *string
func(_value interface{}) {
fmt.Printf("Got: %T", _value)
}(value)
}
// Output: Got: *string |
That's a good idea. Wonder if |
Looks like it has been around since go1, https://pkg.go.dev/fmt@go1 |
The `reflect` package doesn't always know what to call a type in `(reflect.Type).Name()`, but `fmt.Errorf("%T")` always gets it right. Use that so we get actionable error messages.
danhunsaker
force-pushed
the
fix/type-reporting
branch
from
March 25, 2023 00:43
353c146
to
ef7074a
Compare
meatballhat
added
kind/bug
describes or fixes a bug
area/v2
relates to / is being considered for v2
labels
Mar 26, 2023
meatballhat
changed the title
v2 - Fix
Fix Mar 26, 2023
incorrectTypeForFlagError
for unknownsincorrectTypeForFlagError
for unknowns
meatballhat
approved these changes
May 1, 2023
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.
Thank you!
mauromorales
referenced
this pull request
in kairos-io/provider-kairos
May 3, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/urfave/cli/v2](https://togithub.com/urfave/cli) | require | patch | `v2.25.1` -> `v2.25.3` | --- ### Release Notes <details> <summary>urfave/cli</summary> ### [`v2.25.3`](https://togithub.com/urfave/cli/releases/tag/v2.25.3) [Compare Source](https://togithub.com/urfave/cli/compare/v2.25.2...v2.25.3) #### What's Changed - Fix `incorrectTypeForFlagError` for unknowns by [@​danhunsaker](https://togithub.com/danhunsaker) in [https://github.com/urfave/cli/pull/1708](https://togithub.com/urfave/cli/pull/1708) #### New Contributors - [@​danhunsaker](https://togithub.com/danhunsaker) made their first contribution in [https://github.com/urfave/cli/pull/1708](https://togithub.com/urfave/cli/pull/1708) **Full Changelog**: urfave/cli@v2.25.2...v2.25.3 ### [`v2.25.2`](https://togithub.com/urfave/cli/releases/tag/v2.25.2) [Compare Source](https://togithub.com/urfave/cli/compare/v2.25.1...v2.25.2) #### What's Changed - Fix missing required flag error uses flag name and not alias by [@​nirhaas](https://togithub.com/nirhaas) in [https://github.com/urfave/cli/pull/1709](https://togithub.com/urfave/cli/pull/1709) - Remove redundant variable declarations by [@​huiyifyj](https://togithub.com/huiyifyj) in [https://github.com/urfave/cli/pull/1714](https://togithub.com/urfave/cli/pull/1714) - Fix:(issue 1689) Match markdown output with help output by [@​dearchap](https://togithub.com/dearchap) in [https://github.com/urfave/cli/pull/1723](https://togithub.com/urfave/cli/pull/1723) #### New Contributors - [@​nirhaas](https://togithub.com/nirhaas) made their first contribution in [https://github.com/urfave/cli/pull/1709](https://togithub.com/urfave/cli/pull/1709) - [@​huiyifyj](https://togithub.com/huiyifyj) made their first contribution in [https://github.com/urfave/cli/pull/1714](https://togithub.com/urfave/cli/pull/1714) **Full Changelog**: urfave/cli@v2.25.1...v2.25.2 </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 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 [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/kairos-io/provider-kairos). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS42Ni4xIiwidXBkYXRlZEluVmVyIjoiMzUuNjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
reflect
package doesn't always know what to call a type in(reflect.Type).Name()
, but almost always gets it right in(reflect.Type).String()
. Fall back to that so we get actionable error messages.What type of PR is this?
What this PR does / why we need it:
When configs parsed into
MapInputSource
are looked up, they report type mismatch errors, as expected. However, if the type is mismatched for any reason, the error message isn't particularly useful - it reports an "actual type" of''
. This is a known limitation of the way(reflect.Type).Name()
works (it only provides names for package-defined types, not built-in composites or pointers or a handful of other things). Falling back to(reflect.Type).String()
in these cases provides enough data for a developer to fix the actual issue (in this case, using the correct type in theirInputSourceContext
implementation), which is the entire point of returning a type name in that specific error message.v3 doesn't have support for
InputSourceContext
s (or any equivalent I could find), so this fix currently only targets v2.Testing
A test was added to ensure this change works as expected.
Release Notes