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 1.21.0 pass through regression #872

Merged
merged 36 commits into from
Oct 22, 2019
Merged

Conversation

coilysiren
Copy link
Member

@coilysiren coilysiren commented Aug 23, 2019

Changes

  • adds an explicit "regression test" in its own file, distinct from the other tests
  • changes the reorderArgs logic to ignore args that aren't defined for the command you are running
  • refactors reorderArgs for understandability
  • changes a TestCommandFlagParsing test case that was expecting an error, to no longer expect an error

Motivation

Fixes #850

#850 caused a stop everything and fix this now P0 bug that since then taken a few dozen hours of work to fully root-out and stabilize (eg. at my dayjob). Because of that, I've been working to get a change into this package to avoid that occurring in the future.

What I'm looking for here

  • I feel like it's valuable to keep the new regression test I added distinct from the other tests, but do let me know if that doesn't make sense. I'm very ok with moving that test into command_test.go
  • I put a lot of effort into making the logic in reorderArgs as clear as possible, please let me know if I can add more context / docs / update variable names / etc.
  • The change to TestCommandFlagParsing is conceptually dangerous, but in a practical sense I think it's actually safe. Please let me know if you agree or disagree? I think it's safe in a practical sense because user's shouldn't be strictly relying on this package to raise "flag provided but not defined" errors in all kinds of nuanced places.

Future Work

The whole idea of argument re-ordering feels dangerous to me. Immediately after this PR I plan on investigating how I could potentially remove that functionality, without impacting the API.

@codecov
Copy link

codecov bot commented Aug 25, 2019

Codecov Report

Merging #872 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #872      +/-   ##
==========================================
+ Coverage   71.48%   71.64%   +0.16%     
==========================================
  Files          30       30              
  Lines        2395     2409      +14     
==========================================
+ Hits         1712     1726      +14     
  Misses        577      577              
  Partials      106      106
Impacted Files Coverage Δ
command.go 84.02% <100%> (+1.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49ad3df...0480001. Read the comment docs.

@coilysiren coilysiren changed the title (🚧 WIP 🚧) (🚧 WIP 🚧) Fix 1.21.0 pass through regression Aug 25, 2019
@coilysiren
Copy link
Member Author

#691 <= I looks like this PR is what caused the bug, but it doesn't revert cleanly. Which is to be expected, since it's 2 years old 😅 I'll figure this out

@coilysiren
Copy link
Member Author

I believe what happened was that the reorder args functionality here https://github.com/urfave/cli/pull/691/files#diff-9c42b524cb14ca001c61267826cbefb1R206 started accidentally pulling in args meant for pass-through commands. So like the --no-trunc in my regression test.

@coilysiren
Copy link
Member Author

There's a line in the flag re-ordering function that checks for --,

cli/command.go

Line 223 in 6cc7e98

if arg == "--" {
. This hints to me that we already kind of knew that flag re-ordering could cause issues with pass-through commands.

@coilysiren coilysiren self-assigned this Aug 29, 2019
Co-Authored-By: Sascha Grunert <[email protected]>
@coilysiren coilysiren removed the request for review from AudriusButkevicius September 16, 2019 02:56
@coilysiren
Copy link
Member Author

I'm putting this on hold until the v2 released plan is figured out => #826

@coilysiren
Copy link
Member Author

👋 I have returned to this PR

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one non-blocking comment, the rest LGTM

command.go Show resolved Hide resolved
@coilysiren
Copy link
Member Author

review ping @AudriusButkevicius / @asahasrabuddhe

@asahasrabuddhe asahasrabuddhe mentioned this pull request Oct 21, 2019

readFlagValue := false
nextIndexMayContainValue := false
Copy link
Member

@asahasrabuddhe asahasrabuddhe Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nextIndexMayContainValue := false
var nextIndexMayContainValue bool

This is also a possibility as it would be false by default! It's fine if you don't change it too :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna opt against adding this into the PR - but only because I wanna merge this ASAP so that we can fix the regression 🔧

@asahasrabuddhe
Copy link
Member

This looks good 👍 I have added a very optional change. You may or may not choose to do it 😄

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.

Release 1.21.0 regression when using pass-through commands
4 participants