-
Notifications
You must be signed in to change notification settings - Fork 703
cmd/contour: Replace check() by kingpin.Fatalf() in cli.go #2824
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
cmd/contour: Replace check() by kingpin.Fatalf() in cli.go #2824
Conversation
ff4d8cb to
8b9e3b5
Compare
Codecov Report
@@ Coverage Diff @@
## main #2824 +/- ##
==========================================
+ Coverage 76.57% 76.61% +0.03%
==========================================
Files 79 79
Lines 5866 5866
==========================================
+ Hits 4492 4494 +2
+ Misses 1283 1282 -1
+ Partials 91 90 -1
|
jpeach
left a comment
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 code is only used by the contour cli * subcommands, so exiting manually is appropriate here. The log.Fatal in (*Client) dial() is actually a bug.
We have a few options with this code:
- Assume that it is library code and propagate errors out to the caller, who can exit with an error
- Replace
checkwith a functionErrExitwhich does the same thing, but has a clearer name - Replace
checkwith calls to kingpin.FatalIfError - Leave it for now :)
The first option is a fair bit of churn, so you may want to consider the other options :)
|
Hi @jpeach, I find the third option I will also update the existing Thank you for the suggestions. |
3183bdc to
fc9f789
Compare
cmd/contour/cli.go
Outdated
| if ok := certPool.AppendCertsFromPEM(ca); !ok { | ||
| // TODO(nyoung) OMG yuck, thanks for this, crypto/tls. Suggestions on alternates welcomed. | ||
| log.Fatal("failed to append ca certs") | ||
| kingpin.Fatalf("failed to append ca certs") |
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.
I am not very sure about this. I checked kingpins' documentation and could not find kingpin.Fatal. Please advise.
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.
Fatalf seems fine to me. Please update the message to say "CA certificates" instead of "ca certs".
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.
| kingpin.Fatalf("failed to append ca certs") | |
| kingpin.Fatalf("failed to append CA certs") |
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.
@ShaileshSurya ^^^
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.
Fixed this.
fc9f789 to
3d75c25
Compare
jpeach
left a comment
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.
Good progress, just need to update the exit messages. Can you manually trigger some of then and show the output?
Can you please update the log.Fatal on line 48 as well?
cmd/contour/cli.go
Outdated
| certificate, err := tls.LoadX509KeyPair(c.ClientCert, c.ClientKey) | ||
| check(err) | ||
|
|
||
| kingpin.FatalIfError(err, "err: %v", 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.
This will print the error twice, see https://play.golang.org/p/I9qfq3XMT-5
What you want here is:
kingpin.FatalIfError(err, "failed to load key pair")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.
Please update all the other places that format the error.
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.
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.
It's better to provide a message string to give the context of the failure. For example, this:
$ contour cli cds --cafile=/tmp/t --cert-file=/tmp/t --key-file=/tmp/t
contour: error: failed to load CA certificates: open /tmp/t: no such file or directory
is a better message than this:
$ contour cli cds --cafile=/tmp/t --cert-file=/tmp/t --key-file=/tmp/t
contour: error: open /tmp/t: no such file or directory
Could you please add a message string to each call to kingpin.FatalIfError?
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.
Could you please add a message string to each call to
kingpin.FatalIfError?
@ShaileshSurya ^^^
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.
I have made the required changes. We might want to check the wording for each and every error message once.
cmd/contour/cli.go
Outdated
| if ok := certPool.AppendCertsFromPEM(ca); !ok { | ||
| // TODO(nyoung) OMG yuck, thanks for this, crypto/tls. Suggestions on alternates welcomed. | ||
| log.Fatal("failed to append ca certs") | ||
| kingpin.Fatalf("failed to append ca certs") |
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.
Fatalf seems fine to me. Please update the message to say "CA certificates" instead of "ca certs".
3d75c25 to
bc15f89
Compare
There are quite a few places in Contour that call a local check helper that prints to standard error and exits. This approach loses error context and makes it difficult for aggregated log collectors to recognize that this is a fatal error message This commit replaces check functions in cmd/contour/cli.go by kingpin libraries fatal logs Fixes projectcontour#2811 Signed-off-by: Shailesh Suryawanshi <[email protected]>
bc15f89 to
3250d08
Compare
cmd/contour/cli.go
Outdated
| } | ||
| err := st.Send(req) | ||
| check(err) | ||
| kingpin.FatalIfError(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.
Please Check https://play.golang.org/p/1WiDkfYYoLp for the output.
cmd/contour/cli.go
Outdated
| certificate, err := tls.LoadX509KeyPair(c.ClientCert, c.ClientKey) | ||
| check(err) | ||
|
|
||
| kingpin.FatalIfError(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.
Please check https://play.golang.org/p/1WiDkfYYoLp for the output.
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 should be
kingpin.FatalIfError(err, "failed to load certificate")
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.
Made the changes to all FtalIfError. Added Error messages
|
@jpeach I have made the requested changes. Can you please have a look. |
fixing the error message to make more consistent fixes projectcontour#2811 Signed-off-by: Shailesh Suryawanshi <[email protected]>
|
@jpeach Please have a look, I have addressed the review comments. |
jpeach
left a comment
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 looks good, thanks @ShaileshSurya
There are quite a few places in Contour that call a
local check helper that prints to standard error and exits.
This approach loses error context and makes it difficult for
aggregated log collectors to recognize that this is a fatal error message
This commit replaces check functions in cmd/contour/cli.go by log.Fatal
Fixes #2811
Signed-off-by: Shailesh Suryawanshi [email protected]