-
Notifications
You must be signed in to change notification settings - Fork 630
Provide more helpful error message and require input for every non-bool option. #519
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #519 +/- ##
==========================================
+ Coverage 67.06% 67.11% +0.04%
==========================================
Files 37 37
Lines 7622 7627 +5
==========================================
+ Hits 5112 5119 +7
+ Misses 2104 2103 -1
+ Partials 406 405 -1
Continue to review full report at Codecov.
|
Could you include "before" and "after" outputs in the PR description? Basically, enough data for the reviewer to convince themselves that the bug is fixed on all its points. |
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.
Awesome start! Can't wait for this change to get in.
This is just a bookkeeping type nit: Could you mention the issue this is addressing in the PR description?
If a PR fully fixes an issue, adding something like "Fixes #" to the PR description will close the issue automatically when the PR is merged. If the PR only address part of an issue, it's nice to mention if there are next steps.
On
vs.
Casing is inconsistent. User visible messages should use sentence case. |
Actually before was lowercase as well and was consistent throughout the code base, i.e. "unrecognized command ...". Also, my IDE reminds me that error message should not start with uppercase, https://github.com/golang/go/wiki/CodeReviewComments#error-strings |
@wyk9787 I took the example from the PR description. It's fine to keep these lowercase, but the casing should be consistent. |
@aalexand Sorry about! Description is updated. |
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 overall, with a few nits.
Could you also include the output for pprof -help
in the description?
I'd like to be able to check that both interactive and non-interactive help modes produce consistent results.
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.
Still LGTM overall.
internal/driver/commands.go
Outdated
@@ -246,6 +246,22 @@ func helpText(s ...string) string { | |||
return strings.Join(s, "\n") + "\n" | |||
} | |||
|
|||
func variablesPostFix(name string, vr *variable) string { |
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.
The name of this function is unclear. I don't understand what it's doing from the name.
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.
Done.
internal/driver/commands.go
Outdated
@@ -254,7 +270,7 @@ func usage(commandLine bool) string { | |||
prefix = "-" | |||
} | |||
fmtHelp := func(c, d string) string { | |||
return fmt.Sprintf(" %-16s %s", c, strings.SplitN(d, "\n", 2)[0]) | |||
return fmt.Sprintf(" %-22s %s", c, strings.SplitN(d, "\n", 2)[0]) |
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.
Curious: why did 16 change to 22?
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.
To accommodate extra texts (e.g. =) added to the help message and really long option name (i.e. relative_percentages
)
internal/driver/commands.go
Outdated
" Options:\n" | ||
" Options:\n" + | ||
" General format is <option>=<value>\n" + | ||
" <f> is a float, <n> is an integer, and <s> is a string\n\n" |
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.
What about booleans? E.g. how to set a boolean to false?
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.
Done.
Reverted all modifications to the help text and updated description. |
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 overall -- a few nits.
internal/driver/interactive.go
Outdated
@@ -70,6 +70,11 @@ func interactive(p *profile.Profile, o *plugin.Options) error { | |||
value = strings.TrimSpace(value) | |||
} | |||
if v := pprofVariables[name]; v != nil { | |||
// All non-bool options require inputs | |||
if v.kind != boolKind && value == "" { | |||
o.UI.PrintErr(fmt.Errorf("please input a value, e.g. %v", name+"=<val>")) |
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.
Nit:
Here, I think %s would be more idiomatic than %v.
The following would be standard for Golang:
o.UI.PrintErr(fmt.Errorf("please input a value, e.g. %s=<val>", name))
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.
Done.
Really appreciate those comments to help me write better Go code. Thanks!
internal/driver/interactive.go
Outdated
@@ -267,6 +272,9 @@ func parseCommandLine(input []string) ([]string, variables, error) { | |||
} | |||
} | |||
if c == nil { | |||
if v := pprofVariables[name]; v != nil { | |||
return nil, nil, fmt.Errorf(`did you mean: %s?`, name+"="+args[0]) |
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.
Nit: Same as above.
Also nit: I don't think back ticks have added benefit here, so I'd reccomend quotes,
So, following is more idiomatic (assuming args is a slice of strings):
fmt.Errorf("did you mean: %s=%s", name, args[0])
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.
Done.
internal/driver/interactive_test.go
Outdated
{"Random interleave of independent scripts 2", interleave(script, 1), pprofShortcuts, "", 0, false}, | ||
{"Random interleave of independent scripts with shortcuts 1", scScript1, shortcuts1, "", 0, false}, | ||
{"Random interleave of independent scripts with shortcuts 2", scScript2, shortcuts2, "", 0, false}, | ||
{"Group with invalid vale", []string{"cumulative=this"}, pprofShortcuts, `unrecognized value for cumulative: "this". Use one of cum, flat`, 1, false}, |
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.
(super nit) I think this is a typo: vale => value
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.
Done.
internal/driver/interactive_test.go
Outdated
t.Error("expected IO error, got nil") | ||
// Confirm error message written out once. | ||
if tc.numAllowRxMatches != ui.NumAllowRxMatches { | ||
t.Errorf("want error message to be printed %v time(s), got %v", |
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.
Use %d
instead of %v
?
(I know this line already existed, but nice to be able to make it a bit more idiomatic.)
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.
Done.
internal/driver/interactive_test.go
Outdated
} | ||
err := interactive(p, o) | ||
if (tc.propagateError && err == nil) || (tc.propagateError && err != nil) { | ||
t.Errorf("%v: %v", tc.name, err) |
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.
Nit: use %s when possible
t.Errorf("%s: %v", tc.name, err)
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.
Done.
I would probably leave out that part of changing the help message. (And revert the header of the options section as needed) |
Yes, already reverted all changes made to the help message. There is no modification to the help message in this PR and the description is updated as well. |
shortcuts shortcuts | ||
allowRx string | ||
numAllowRxMatches int | ||
propagateError bool |
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.
This flag seems to be false in all test cases, is this expected?
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.
Now fixed.
The conditional logic on line 79 was incorrect and is fixed now.
internal/driver/interactive.go
Outdated
@@ -70,6 +70,11 @@ func interactive(p *profile.Profile, o *plugin.Options) error { | |||
value = strings.TrimSpace(value) | |||
} | |||
if v := pprofVariables[name]; v != nil { | |||
// All non-bool options require inputs | |||
if v.kind != boolKind && value == "" { | |||
o.UI.PrintErr(fmt.Errorf("please input a value, e.g. %s=<val>", name)) |
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.
input -> specify
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.
Done.
@wyk9787 The travis build is failing? |
It seems like the Travis times out before the test is even run: https://travis-ci.org/github/google/pprof/jobs/675881270. Is it possible to increase the time limit for travis? Currently it's set to 50 minutes. |
For now, I restarted the errored tests. Can other folks restart these tests, too? |
I don't think I am able to. |
@aalexand The Travis build just passed. |
Bump from 20191205061153 => 20201109224723 My personal interest is to pull in google/pprof#564, which adds support for displaying names with `"` in them, which julia functions sometimes have (e.g. `var"#foo#23"`) Includes: - google/pprof#564 - google/pprof#575 - google/pprof#574 - google/pprof#571 - google/pprof#572 - google/pprof#570 - google/pprof#562 - google/pprof#561 - google/pprof#565 - google/pprof#560 - google/pprof#563 - google/pprof#557 - google/pprof#554 - google/pprof#552 - google/pprof#545 - google/pprof#549 - google/pprof#547 - google/pprof#541 - google/pprof#534 - google/pprof#542 - google/pprof#535 - google/pprof#531 - google/pprof#530 - google/pprof#528 - google/pprof#522 - google/pprof#525 - google/pprof#527 - google/pprof#519 - google/pprof#520 - google/pprof#517 - google/pprof#518 - google/pprof#514 - google/pprof#513 - google/pprof#510 - google/pprof#508 - google/pprof#506 - google/pprof#509 - google/pprof#504
* Update pprof to latest revision Bump from 20191205061153 => 20201109224723 My personal interest is to pull in google/pprof#564, which adds support for displaying names with `"` in them, which julia functions sometimes have (e.g. `var"#foo#23"`) Includes: - google/pprof#564 - google/pprof#575 - google/pprof#574 - google/pprof#571 - google/pprof#572 - google/pprof#570 - google/pprof#562 - google/pprof#561 - google/pprof#565 - google/pprof#560 - google/pprof#563 - google/pprof#557 - google/pprof#554 - google/pprof#552 - google/pprof#545 - google/pprof#549 - google/pprof#547 - google/pprof#541 - google/pprof#534 - google/pprof#542 - google/pprof#535 - google/pprof#531 - google/pprof#530 - google/pprof#528 - google/pprof#522 - google/pprof#525 - google/pprof#527 - google/pprof#519 - google/pprof#520 - google/pprof#517 - google/pprof#518 - google/pprof#514 - google/pprof#513 - google/pprof#510 - google/pprof#508 - google/pprof#506 - google/pprof#509 - google/pprof#504 * Update P/pprof/build_tarballs.jl - use a real version number Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> * Remove now unused `timestamp` * [pprof] Use `GitSource` Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
…ol option. (google#519) Provide more helpful error message and require input for every non-bool option.
Fixes: #441
Before:
After: