Skip to content

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

Merged
merged 22 commits into from
Apr 17, 2020

Conversation

wyk9787
Copy link
Contributor

@wyk9787 wyk9787 commented Apr 8, 2020

Fixes: #441

  1. More helpful error messages and usages are added.
  2. All non-bool option now requires an input. That means "call_tree" is valid, but "sample_index" is invalid.

Before:

(pprof) sample_index
(pprof)
(pprof) sample_index 0
unrecognized command: "sample_index"
(pprof) help
    ...
    sample_index     Sample value to report (0-based index or name)
    ...

After:

(pprof) sample_index
please input a value, e.g. sample_index=<val>
(pprof) focus
please input a value, e.g. focus=<val>
(pprof) call_tree
(pprof) 
(pprof) sample_index 0
do you mean: "sample_index=0"?

@codecov-io
Copy link

codecov-io commented Apr 8, 2020

Codecov Report

Merging #519 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
internal/driver/interactive.go 61.65% <100.00%> (+1.50%) ⬆️

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 b1a9688...fc94335. Read the comment docs.

@aalexand
Copy link
Collaborator

aalexand commented Apr 8, 2020

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.

Copy link
Contributor

@nolanmar511 nolanmar511 left a 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.

@aalexand
Copy link
Collaborator

aalexand commented Apr 9, 2020

On

(pprof) sample_index 0
Unrecognized command: "sample_index"

vs.

(pprof) sample_index
please input a value, e.g. option = value

(pprof) focus
please input a value, e.g. option = value

(pprof) sample_index 0
do you mean: "sample_index=0"?

Casing is inconsistent. User visible messages should use sentence case.

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 9, 2020

On

(pprof) sample_index 0
Unrecognized command: "sample_index"

vs.

(pprof) sample_index
please input a value, e.g. option = value

(pprof) focus
please input a value, e.g. option = value

(pprof) sample_index 0
do you mean: "sample_index=0"?

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

@aalexand
Copy link
Collaborator

aalexand commented Apr 9, 2020

On

(pprof) sample_index 0
Unrecognized command: "sample_index"

vs.

(pprof) sample_index
please input a value, e.g. option = value

(pprof) focus
please input a value, e.g. option = value

(pprof) sample_index 0
do you mean: "sample_index=0"?

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.

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 9, 2020

On

(pprof) sample_index 0
Unrecognized command: "sample_index"

vs.

(pprof) sample_index
please input a value, e.g. option = value

(pprof) focus
please input a value, e.g. option = value

(pprof) sample_index 0
do you mean: "sample_index=0"?

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.

Copy link
Contributor

@nolanmar511 nolanmar511 left a 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.

Copy link
Contributor

@nolanmar511 nolanmar511 left a comment

Choose a reason for hiding this comment

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

Still LGTM overall.

nolanmar511
nolanmar511 previously approved these changes Apr 10, 2020
@@ -246,6 +246,22 @@ func helpText(s ...string) string {
return strings.Join(s, "\n") + "\n"
}

func variablesPostFix(name string, vr *variable) string {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -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])
Copy link
Collaborator

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?

Copy link
Contributor Author

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)

" 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"
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 13, 2020

Reverted all modifications to the help text and updated description.

Copy link
Contributor

@nolanmar511 nolanmar511 left a 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.

@@ -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>"))
Copy link
Contributor

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))

Copy link
Contributor Author

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!

@@ -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])
Copy link
Contributor

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])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

{"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},
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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",
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
err := interactive(p, o)
if (tc.propagateError && err == nil) || (tc.propagateError && err != nil) {
t.Errorf("%v: %v", tc.name, err)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

nolanmar511
nolanmar511 previously approved these changes Apr 14, 2020
@wyk9787 wyk9787 closed this Apr 15, 2020
@wyk9787 wyk9787 deleted the helpful_error branch April 15, 2020 01:15
@wyk9787 wyk9787 restored the helpful_error branch April 15, 2020 01:15
@wyk9787 wyk9787 reopened this Apr 15, 2020
@aalexand
Copy link
Collaborator

Or, I should simply discard those changes for the help in this PR?

I would probably leave out that part of changing the help message. (And revert the header of the options section as needed)

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 15, 2020

Or, I should simply discard those changes for the help in this PR?

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

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

input -> specify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@aalexand
Copy link
Collaborator

@wyk9787 The travis build is failing?

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 16, 2020

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

@nolanmar511
Copy link
Contributor

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

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 16, 2020

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

@wyk9787
Copy link
Contributor Author

wyk9787 commented Apr 17, 2020

@aalexand The Travis build just passed.

@aalexand aalexand merged commit c6e0a84 into google:master Apr 17, 2020
@wyk9787 wyk9787 deleted the helpful_error branch April 30, 2020 17:02
giordano added a commit to JuliaPackaging/Yggdrasil that referenced this pull request Nov 13, 2020
* 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>
gmarin13 pushed a commit to gmarin13/pprof that referenced this pull request Dec 17, 2020
…ol option. (google#519)

Provide more helpful error message and require input for every non-bool option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command line error messages could be more helpful
5 participants